|
|
1.1 root 1: /*
2: * Copyright (c) 1983, 1988 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)timer.c 5.9 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: /*
25: * Routing Table Management Daemon
26: */
27: #include "defs.h"
28:
29: int faketime;
30:
31: /*
32: * Timer routine. Performs routing information supply
33: * duties and manages timers on routing table entries.
34: * Management of the RTS_CHANGED bit assumes that we broadcast
35: * each time called.
36: */
37: timer()
38: {
39: register struct rthash *rh;
40: register struct rt_entry *rt;
41: struct rthash *base = hosthash;
42: int doinghost = 1, timetobroadcast;
43: extern int externalinterfaces;
44:
45: (void) gettimeofday(&now, (struct timezone *)NULL);
46: faketime += TIMER_RATE;
47: if (lookforinterfaces && (faketime % CHECK_INTERVAL) == 0)
48: ifinit();
49: timetobroadcast = supplier && (faketime % SUPPLY_INTERVAL) == 0;
50: again:
51: for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
52: rt = rh->rt_forw;
53: for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
54: /*
55: * We don't advance time on a routing entry for
56: * a passive gateway, or any interface if we're
57: * not acting as supplier.
58: */
59: if (!(rt->rt_state & RTS_PASSIVE) &&
60: (supplier || !(rt->rt_state & RTS_INTERFACE)))
61: rt->rt_timer += TIMER_RATE;
62: if (rt->rt_timer >= GARBAGE_TIME) {
63: rt = rt->rt_back;
64: rtdelete(rt->rt_forw);
65: continue;
66: }
67: if (rt->rt_timer >= EXPIRE_TIME &&
68: rt->rt_metric < HOPCNT_INFINITY)
69: rtchange(rt, &rt->rt_router, HOPCNT_INFINITY);
70: rt->rt_state &= ~RTS_CHANGED;
71: }
72: }
73: if (doinghost) {
74: doinghost = 0;
75: base = nethash;
76: goto again;
77: }
78: if (timetobroadcast) {
79: toall(supply, 0, (struct interface *)NULL);
80: lastbcast = now;
81: lastfullupdate = now;
82: needupdate = 0; /* cancel any pending dynamic update */
83: nextbcast.tv_sec = 0;
84: }
85: }
86:
87: /*
88: * On hangup, let everyone know we're going away.
89: */
90: hup()
91: {
92: register struct rthash *rh;
93: register struct rt_entry *rt;
94: struct rthash *base = hosthash;
95: int doinghost = 1;
96:
97: if (supplier) {
98: again:
99: for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
100: rt = rh->rt_forw;
101: for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
102: rt->rt_metric = HOPCNT_INFINITY;
103: }
104: if (doinghost) {
105: doinghost = 0;
106: base = nethash;
107: goto again;
108: }
109: toall(supply, 0, (struct interface *)NULL);
110: }
111: exit(1);
112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.