* Copyright (c) 1983, 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)timer.c 5.7 (Berkeley) %G%";
* Routing Table Management Daemon
int timeval
= -TIMER_RATE
;
* Timer routine. Performs routing information supply
* duties and manages timers on routing table entries.
register struct rthash
*rh
;
register struct rt_entry
*rt
;
struct rthash
*base
= hosthash
;
int doinghost
= 1, timetobroadcast
, changes
= 0;
extern int externalinterfaces
;
if (lookforinterfaces
&& (timeval
% CHECK_INTERVAL
) == 0)
timetobroadcast
= supplier
&& (timeval
% SUPPLY_INTERVAL
) == 0;
for (rh
= base
; rh
< &base
[ROUTEHASHSIZ
]; rh
++) {
for (; rt
!= (struct rt_entry
*)rh
; rt
= rt
->rt_forw
) {
* We don't advance time on a routing entry for
* a passive gateway, or any interface if we're
* not acting as supplier.
if (!(rt
->rt_state
& RTS_PASSIVE
) &&
(supplier
|| !(rt
->rt_state
& RTS_INTERFACE
)))
rt
->rt_timer
+= TIMER_RATE
;
if (rt
->rt_timer
>= GARBAGE_TIME
) {
if (rt
->rt_timer
>= EXPIRE_TIME
) {
if (traceactions
&& changes
++ == 0) {
rtchange(rt
, &rt
->rt_router
, HOPCNT_INFINITY
);
if (rt
->rt_state
& RTS_CHANGED
) {
rt
->rt_state
&= ~RTS_CHANGED
;
/* don't send extraneous packets */
if (!supplier
|| timetobroadcast
)
msg
->rip_cmd
= RIPCMD_RESPONSE
;
msg
->rip_vers
= RIPVERSION
;
msg
->rip_nets
[0].rip_dst
= rt
->rt_dst
;
msg
->rip_nets
[0].rip_dst
.sa_family
=
htons(msg
->rip_nets
[0].rip_dst
.sa_family
);
msg
->rip_nets
[0].rip_metric
=
htonl(min(rt
->rt_metric
, HOPCNT_INFINITY
));
* On hangup, let everyone know we're going away.
register struct rthash
*rh
;
register struct rt_entry
*rt
;
struct rthash
*base
= hosthash
;
for (rh
= base
; rh
< &base
[ROUTEHASHSIZ
]; rh
++) {
for (; rt
!= (struct rt_entry
*)rh
; rt
= rt
->rt_forw
)
rt
->rt_metric
= HOPCNT_INFINITY
;