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
38 * $FreeBSD: src/usr.sbin/IPXrouted/timer.c,v 1.5 1999/08/28 01:15:06 peter Exp $
39 * $DragonFly: src/usr.sbin/IPXrouted/timer.c,v 1.3 2004/03/11 09:38:59 hmp Exp $
41 * @(#)timer.c 8.1 (Berkeley) 6/5/93
45 * Routing Table Management Daemon
51 int timeval
= -TIMER_RATE
;
54 * Timer routine. Performs routing information supply
55 * duties and manages timers on routing and SAP table entries.
63 struct sap_entry
*sap
;
64 struct sap_hash
*sap_base
= sap_head
;
65 int timetobroadcast
, ripbroadcast
, sapbroadcast
;
67 timeval
+= TIMER_RATE
;
68 if (lookforinterfaces
&& (timeval
% CHECK_INTERVAL
) == 0)
70 timetobroadcast
= supplier
&& (timeval
% SUPPLY_INTERVAL
) == 0;
71 ripbroadcast
= supplier
&& timetobroadcast
&&
72 (timeval
% RIP_INTERVAL
) == 0;
73 sapbroadcast
= timetobroadcast
&& dosap
&& !ripbroadcast
;
75 for (rh
= nethash
; rh
< &nethash
[ROUTEHASHSIZ
]; rh
++) {
77 for (; rt
!= (struct rt_entry
*)rh
; rt
= rt
->rt_forw
) {
79 struct rt_entry
*trt
, *prt
;
81 * If a clone expire free it and mark the
82 * main route RTS_CHANGED.
87 trt
->rt_timer
+= TIMER_RATE
;
88 if (trt
->rt_timer
>= EXPIRE_TIME
) {
89 prt
->rt_clone
= trt
->rt_clone
;
92 rt
->rt_state
|= RTS_CHANGED
;
100 * We don't advance time on a routing entry for
101 * a passive gateway or that for our only interface.
102 * The latter is excused because we don't act as
103 * a routing information supplier and hence would
104 * time it out. This is fair as if it's down
105 * we're cut off from the world anyway and it's
106 * not likely we'll grow any new hardware in
109 if (!(rt
->rt_state
& RTS_PASSIVE
) &&
110 !(rt
->rt_state
& RTS_INTERFACE
))
111 rt
->rt_timer
+= TIMER_RATE
;
112 if (rt
->rt_timer
>= EXPIRE_TIME
) {
113 rt
->rt_metric
= HOPCNT_INFINITY
;
114 rt
->rt_state
|= RTS_CHANGED
;
116 if (rt
->rt_timer
>= GARBAGE_TIME
) {
118 /* Perhaps we should send a REQUEST for this route? */
119 rtdelete(rt
->rt_forw
);
122 if (rt
->rt_state
& RTS_CHANGED
) {
123 rt
->rt_state
&= ~RTS_CHANGED
;
124 /* don't send extraneous packets */
125 if (!supplier
|| ripbroadcast
)
127 if ((rt
->rt_metric
+ 1) == HOPCNT_INFINITY
)
129 msg
->rip_cmd
= htons(RIPCMD_RESPONSE
);
130 msg
->rip_nets
[0].rip_dst
=
131 (satoipx_addr(rt
->rt_dst
)).x_net
;
132 msg
->rip_nets
[0].rip_metric
=
133 htons(min(rt
->rt_metric
+1, HOPCNT_INFINITY
));
134 msg
->rip_nets
[0].rip_ticks
=
135 htons(rt
->rt_ticks
+ 1);
136 toall(sndmsg
, rt
, 0);
141 toall(supply
, NULL
, 0);
144 * Now do the SAP stuff.
146 for (sh
= sap_base
; sh
< &sap_base
[SAPHASHSIZ
]; sh
++) {
148 for (; sap
!= (struct sap_entry
*)sh
; sap
= sap
->forw
) {
150 struct sap_entry
*tsap
, *psap
;
152 * If a clone expire free it and mark the
153 * main sap entry RTS_CHANGED.
158 tsap
->timer
+= TIMER_RATE
;
159 if (tsap
->timer
>= EXPIRE_TIME
) {
160 psap
->clone
= tsap
->clone
;
163 sap
->state
|= RTS_CHANGED
;
170 sap
->timer
+= TIMER_RATE
;
171 if (sap
->timer
>= EXPIRE_TIME
) {
172 sap
->sap
.hops
= htons(HOPCNT_INFINITY
);
173 sap
->state
|= RTS_CHANGED
;
175 if (sap
->timer
>= GARBAGE_TIME
) {
177 /* Perhaps we should send a REQUEST for this route? */
178 sap_delete(sap
->forw
);
182 * XXX sap_sndmsg on RTS_CHANGED
184 if (sap
->state
& RTS_CHANGED
) {
185 sap
->state
&= ~RTS_CHANGED
;
187 /* don't send extraneous packets */
188 if (!supplier
|| sapbroadcast
)
190 if ((ntohs(sap
->sap
.hops
) + 1) == HOPCNT_INFINITY
)
192 sap_msg
->sap_cmd
= htons(SAP_RESP
);
193 sap_msg
->sap
[0] = sap
->sap
;
194 sap_msg
->sap
[0].hops
=
195 htons(min(sap
->sap
.hops
+1, HOPCNT_INFINITY
));
196 toall(sapsndmsg
, rt
, 0);
203 if (ftrace
&& sapbroadcast
)
204 dumpsaptable(ftrace
, sap_head
);
208 * On hangup, let everyone know we're going away.
216 struct sap_entry
*sap
;
219 for (rh
= nethash
; rh
< &nethash
[ROUTEHASHSIZ
]; rh
++) {
221 for (; rt
!= (struct rt_entry
*)rh
; rt
= rt
->rt_forw
)
222 rt
->rt_metric
= HOPCNT_INFINITY
;
224 toall(supply
, NULL
, 0);
229 for (sh
= sap_head
; sh
< &sap_head
[SAPHASHSIZ
]; sh
++) {
231 for (; sap
!= (struct sap_entry
*)sh
; sap
= sap
->forw
)
232 sap
->sap
.hops
= htons(HOPCNT_INFINITY
);