Oh GACK! src-clean doesn't quite work that easily since cleandist rebuilds the
[unix-history] / sbin / XNSrouted / timer.c
CommitLineData
18916298
RG
1/*
2 * Copyright (c) 1985 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This file includes significant work done at Cornell University by
6 * Bill Nesheim. That work included by permission.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38static char sccsid[] = "@(#)timer.c 5.7 (Berkeley) 2/26/91";
39#endif /* not lint */
40
41/*
42 * Routing Table Management Daemon
43 */
44#include "defs.h"
45
46int timeval = -TIMER_RATE;
47
48/*
49 * Timer routine. Performs routing information supply
50 * duties and manages timers on routing table entries.
51 */
52void
53timer()
54{
55 register struct rthash *rh;
56 register struct rt_entry *rt;
57 struct rthash *base = hosthash;
58 int doinghost = 1, timetobroadcast;
59
60 timeval += TIMER_RATE;
61 if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
62 ifinit();
63 timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
64again:
65 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
66 rt = rh->rt_forw;
67 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
68 /*
69 * We don't advance time on a routing entry for
70 * a passive gateway or that for our only interface.
71 * The latter is excused because we don't act as
72 * a routing information supplier and hence would
73 * time it out. This is fair as if it's down
74 * we're cut off from the world anyway and it's
75 * not likely we'll grow any new hardware in
76 * the mean time.
77 */
78 if (!(rt->rt_state & RTS_PASSIVE) &&
79 (supplier || !(rt->rt_state & RTS_INTERFACE)))
80 rt->rt_timer += TIMER_RATE;
81 if (rt->rt_timer >= EXPIRE_TIME)
82 rt->rt_metric = HOPCNT_INFINITY;
83 if (rt->rt_timer >= GARBAGE_TIME) {
84 rt = rt->rt_back;
85 /* Perhaps we should send a REQUEST for this route? */
86 rtdelete(rt->rt_forw);
87 continue;
88 }
89 if (rt->rt_state & RTS_CHANGED) {
90 rt->rt_state &= ~RTS_CHANGED;
91 /* don't send extraneous packets */
92 if (!supplier || timetobroadcast)
93 continue;
94 msg->rip_cmd = htons(RIPCMD_RESPONSE);
95 msg->rip_nets[0].rip_dst =
96 (satons_addr(rt->rt_dst)).x_net;
97 msg->rip_nets[0].rip_metric =
98 htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
99 toall(sndmsg);
100 }
101 }
102 }
103 if (doinghost) {
104 doinghost = 0;
105 base = nethash;
106 goto again;
107 }
108 if (timetobroadcast)
109 toall(supply);
110 alarm(TIMER_RATE);
111}
112
113/*
114 * On hangup, let everyone know we're going away.
115 */
116void
117hup()
118{
119 register struct rthash *rh;
120 register struct rt_entry *rt;
121 struct rthash *base = hosthash;
122 int doinghost = 1;
123
124 if (supplier) {
125again:
126 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
127 rt = rh->rt_forw;
128 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
129 rt->rt_metric = HOPCNT_INFINITY;
130 }
131 if (doinghost) {
132 doinghost = 0;
133 base = nethash;
134 goto again;
135 }
136 toall(supply);
137 }
138 exit(1);
139}