* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at 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'' without express or implied warranty.
static char sccsid
[] = "@(#)timer.c 5.5 (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
;
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
)
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
+ rt
->rt_ifmetric
,
* 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
;