2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1995 John Hay. All rights reserved.
7 * This file includes significant work done at Cornell University by
8 * Bill Nesheim. That work included by permission.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 static const char sccsid[] = "@(#)timer.c 8.1 (Berkeley) 6/5/93";
46 * Routing Table Management Daemon
52 int timeval = -TIMER_RATE;
55 * Timer routine. Performs routing information supply
56 * duties and manages timers on routing and SAP table entries.
61 register struct rthash *rh;
62 register struct rt_entry *rt;
63 register struct sap_hash *sh;
64 register struct sap_entry *sap;
65 struct sap_hash *sap_base = sap_head;
66 int timetobroadcast, ripbroadcast, sapbroadcast;
68 timeval += TIMER_RATE;
69 if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
71 timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
72 ripbroadcast = supplier && timetobroadcast &&
73 (timeval % RIP_INTERVAL) == 0;
74 sapbroadcast = timetobroadcast && dosap && !ripbroadcast;
76 for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) {
78 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
80 struct rt_entry *trt, *prt;
82 * If a clone expire free it and mark the
83 * main route RTS_CHANGED.
88 trt->rt_timer += TIMER_RATE;
89 if (trt->rt_timer >= EXPIRE_TIME) {
90 prt->rt_clone = trt->rt_clone;
93 rt->rt_state |= RTS_CHANGED;
101 * We don't advance time on a routing entry for
102 * a passive gateway or that for our only interface.
103 * The latter is excused because we don't act as
104 * a routing information supplier and hence would
105 * time it out. This is fair as if it's down
106 * we're cut off from the world anyway and it's
107 * not likely we'll grow any new hardware in
110 if (!(rt->rt_state & RTS_PASSIVE) &&
111 !(rt->rt_state & RTS_INTERFACE))
112 rt->rt_timer += TIMER_RATE;
113 if (rt->rt_timer >= EXPIRE_TIME) {
114 rt->rt_metric = HOPCNT_INFINITY;
115 rt->rt_state |= RTS_CHANGED;
117 if (rt->rt_timer >= GARBAGE_TIME) {
119 /* Perhaps we should send a REQUEST for this route? */
120 rtdelete(rt->rt_forw);
123 if (rt->rt_state & RTS_CHANGED) {
124 rt->rt_state &= ~RTS_CHANGED;
125 /* don't send extraneous packets */
126 if (!supplier || ripbroadcast)
128 if ((rt->rt_metric + 1) == HOPCNT_INFINITY)
130 msg->rip_cmd = htons(RIPCMD_RESPONSE);
131 msg->rip_nets[0].rip_dst =
132 (satoipx_addr(rt->rt_dst)).x_net;
133 msg->rip_nets[0].rip_metric =
134 htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
135 msg->rip_nets[0].rip_ticks =
136 htons(rt->rt_ticks + 1);
137 toall(sndmsg, rt, 0);
142 toall(supply, NULL, 0);
145 * Now do the SAP stuff.
147 for (sh = sap_base; sh < &sap_base[SAPHASHSIZ]; sh++) {
149 for (; sap != (struct sap_entry *)sh; sap = sap->forw) {
151 struct sap_entry *tsap, *psap;
153 * If a clone expire free it and mark the
154 * main sap entry RTS_CHANGED.
159 tsap->timer += TIMER_RATE;
160 if (tsap->timer >= EXPIRE_TIME) {
161 psap->clone = tsap->clone;
164 sap->state |= RTS_CHANGED;
171 sap->timer += TIMER_RATE;
172 if (sap->timer >= EXPIRE_TIME) {
173 sap->sap.hops = htons(HOPCNT_INFINITY);
174 sap->state |= RTS_CHANGED;
176 if (sap->timer >= GARBAGE_TIME) {
178 /* Perhaps we should send a REQUEST for this route? */
179 sap_delete(sap->forw);
183 * XXX sap_sndmsg on RTS_CHANGED
185 if (sap->state & RTS_CHANGED) {
186 sap->state &= ~RTS_CHANGED;
188 /* don't send extraneous packets */
189 if (!supplier || sapbroadcast)
191 if ((ntohs(sap->sap.hops) + 1) == HOPCNT_INFINITY)
193 sap_msg->sap_cmd = htons(SAP_RESP);
194 sap_msg->sap[0] = sap->sap;
195 sap_msg->sap[0].hops =
196 htons(min(sap->sap.hops+1, HOPCNT_INFINITY));
197 toall(sapsndmsg, rt, 0);
204 if (ftrace && sapbroadcast)
205 dumpsaptable(ftrace, sap_head);
209 * On hangup, let everyone know we're going away.
214 register struct rthash *rh;
215 register struct rt_entry *rt;
216 register struct sap_hash *sh;
217 register struct sap_entry *sap;
220 for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) {
222 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
223 rt->rt_metric = HOPCNT_INFINITY;
225 toall(supply, NULL, 0);
230 for (sh = sap_head; sh < &sap_head[SAPHASHSIZ]; sh++) {
232 for (; sap != (struct sap_entry *)sh; sap = sap->forw)
233 sap->sap.hops = htons(HOPCNT_INFINITY);