4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * Routing Table Management Daemon
42 int supplyinterval
; /* current supply interval */
45 * Timer routine. Performs routing information supply
46 * duties and manages timers on routing table entries.
47 * Management of the RTS_CHANGED bit assumes that we multicast
55 boolean_t timetomulticast
= _B_FALSE
;
57 static int iftime
; /* interface timer */
58 static int mtime
; /* periodic mcast supply timer */
59 static int alarmtime
= 0; /* time elapsed since last call */
60 int mintime
; /* tracks when next timer will expire */
63 * On the initial call to timer(), the various times that are kept track
64 * of need to be initialized. After initializing everything, "remember"
65 * (via a static) how long until the next timer expires.
68 supplyinterval
= GET_RANDOM(MIN_SUPPLY_TIME
, MAX_SUPPLY_TIME
);
70 mtime
= supplyinterval
;
71 alarmtime
= supplyinterval
;
72 (void) alarm(alarmtime
);
77 * Initialize mintime to a suitable "large" value and then compare it to
78 * other times in the future to determine which event will occur next.
81 (void) sighold(SIGHUP
);
82 (void) sighold(SIGUSR1
);
83 (void) sighold(SIGUSR2
);
86 if (iftime
>= CHECK_INTERVAL
) {
90 mintime
= min(mintime
, CHECK_INTERVAL
- iftime
);
93 if (mtime
>= supplyinterval
) {
95 timetomulticast
= _B_TRUE
;
97 supplyinterval
= GET_RANDOM(MIN_SUPPLY_TIME
, MAX_SUPPLY_TIME
);
99 mintime
= min(mintime
, supplyinterval
- mtime
);
101 for (i
= IPV6_ABITS
; i
>= 0; i
--) {
102 if (net_hashes
[i
] == NULL
)
105 for (rh
= net_hashes
[i
];
106 rh
< &net_hashes
[i
][ROUTEHASHSIZ
]; rh
++) {
107 for (rt
= rh
->rt_forw
; rt
!= (struct rt_entry
*)rh
;
110 * We don't advance time on a routing entry for
111 * an interface because we catch
112 * interfaces going up and down in initifs.
114 rt
->rt_state
&= ~RTS_CHANGED
;
115 if ((rt
->rt_state
& RTS_INTERFACE
) != 0)
117 rt
->rt_timer
+= alarmtime
;
118 if (rt
->rt_timer
>= GARBAGE_TIME
) {
120 rtdelete(rt
->rt_forw
);
123 if (rt
->rt_timer
>= EXPIRE_TIME
) {
125 mintime
= min(mintime
,
126 GARBAGE_TIME
- rt
->rt_timer
);
128 mintime
= min(mintime
,
129 EXPIRE_TIME
- rt
->rt_timer
);
135 if (timetomulticast
) {
136 supplyall(&allrouters
, 0, NULL
, _B_TRUE
);
137 (void) gettimeofday(&now
, NULL
);
139 lastfullupdate
= now
;
140 needupdate
= _B_FALSE
; /* cancel any pending dynamic update */
141 nextmcast
.tv_sec
= 0;
143 (void) sigrelse(SIGUSR2
);
144 (void) sigrelse(SIGUSR1
);
145 (void) sigrelse(SIGHUP
);
148 * "Remember" (via a static) how long until the next timer expires.
151 (void) alarm(alarmtime
);
155 * On SIGTERM, let everyone know we're going away.
166 for (i
= IPV6_ABITS
; i
>= 0; i
--) {
167 if (net_hashes
[i
] == NULL
)
170 for (rh
= net_hashes
[i
]; rh
< &net_hashes
[i
][ROUTEHASHSIZ
];
172 for (rt
= rh
->rt_forw
; rt
!= (struct rt_entry
*)rh
;
174 rt
->rt_metric
= HOPCNT_INFINITY
;
178 supplyall(&allrouters
, 0, NULL
, _B_TRUE
);
179 (void) unlink(PATH_PID
);