Commit | Line | Data |
---|---|---|
5ff67f98 | 1 | /* |
f6048f23 | 2 | * Copyright (c) 1983, 1988 Regents of the University of California. |
0eb85d71 KB |
3 | * All rights reserved. |
4 | * | |
d60d530a | 5 | * %sccs.include.redist.c% |
5ff67f98 DF |
6 | */ |
7 | ||
5919db1b | 8 | #ifndef lint |
d60d530a | 9 | static char sccsid[] = "@(#)timer.c 5.9 (Berkeley) %G%"; |
0eb85d71 | 10 | #endif /* not lint */ |
5919db1b SL |
11 | |
12 | /* | |
13 | * Routing Table Management Daemon | |
14 | */ | |
7fe7fe74 | 15 | #include "defs.h" |
5919db1b | 16 | |
4033c8f6 | 17 | int faketime; |
5919db1b SL |
18 | |
19 | /* | |
20 | * Timer routine. Performs routing information supply | |
21 | * duties and manages timers on routing table entries. | |
4033c8f6 MK |
22 | * Management of the RTS_CHANGED bit assumes that we broadcast |
23 | * each time called. | |
5919db1b SL |
24 | */ |
25 | timer() | |
26 | { | |
27 | register struct rthash *rh; | |
28 | register struct rt_entry *rt; | |
29 | struct rthash *base = hosthash; | |
4033c8f6 | 30 | int doinghost = 1, timetobroadcast; |
604bfd52 | 31 | extern int externalinterfaces; |
5919db1b | 32 | |
4033c8f6 MK |
33 | (void) gettimeofday(&now, (struct timezone *)NULL); |
34 | faketime += TIMER_RATE; | |
35 | if (lookforinterfaces && (faketime % CHECK_INTERVAL) == 0) | |
5919db1b | 36 | ifinit(); |
4033c8f6 | 37 | timetobroadcast = supplier && (faketime % SUPPLY_INTERVAL) == 0; |
5919db1b SL |
38 | again: |
39 | for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { | |
40 | rt = rh->rt_forw; | |
41 | for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { | |
42 | /* | |
43 | * We don't advance time on a routing entry for | |
4ff053a6 MK |
44 | * a passive gateway, or any interface if we're |
45 | * not acting as supplier. | |
5919db1b SL |
46 | */ |
47 | if (!(rt->rt_state & RTS_PASSIVE) && | |
4ff053a6 | 48 | (supplier || !(rt->rt_state & RTS_INTERFACE))) |
5919db1b | 49 | rt->rt_timer += TIMER_RATE; |
5919db1b SL |
50 | if (rt->rt_timer >= GARBAGE_TIME) { |
51 | rt = rt->rt_back; | |
52 | rtdelete(rt->rt_forw); | |
53 | continue; | |
54 | } | |
4033c8f6 MK |
55 | if (rt->rt_timer >= EXPIRE_TIME && |
56 | rt->rt_metric < HOPCNT_INFINITY) | |
88709531 | 57 | rtchange(rt, &rt->rt_router, HOPCNT_INFINITY); |
4033c8f6 | 58 | rt->rt_state &= ~RTS_CHANGED; |
5919db1b SL |
59 | } |
60 | } | |
61 | if (doinghost) { | |
62 | doinghost = 0; | |
63 | base = nethash; | |
64 | goto again; | |
65 | } | |
4033c8f6 MK |
66 | if (timetobroadcast) { |
67 | toall(supply, 0, (struct interface *)NULL); | |
68 | lastbcast = now; | |
69 | lastfullupdate = now; | |
70 | needupdate = 0; /* cancel any pending dynamic update */ | |
71 | nextbcast.tv_sec = 0; | |
72 | } | |
5919db1b | 73 | } |
b7e4f8be MK |
74 | |
75 | /* | |
76 | * On hangup, let everyone know we're going away. | |
77 | */ | |
78 | hup() | |
79 | { | |
80 | register struct rthash *rh; | |
81 | register struct rt_entry *rt; | |
82 | struct rthash *base = hosthash; | |
83 | int doinghost = 1; | |
84 | ||
85 | if (supplier) { | |
86 | again: | |
87 | for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { | |
88 | rt = rh->rt_forw; | |
89 | for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) | |
90 | rt->rt_metric = HOPCNT_INFINITY; | |
91 | } | |
92 | if (doinghost) { | |
93 | doinghost = 0; | |
94 | base = nethash; | |
95 | goto again; | |
96 | } | |
4033c8f6 | 97 | toall(supply, 0, (struct interface *)NULL); |
b7e4f8be MK |
98 | } |
99 | exit(1); | |
100 | } |