dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.lib / in.ripngd / timer.c
blobfb4ad73b3a3e1cf00cab04773ac8ba8f56a32a9a
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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
40 #include "defs.h"
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
48 * each time called.
50 void
51 timer(void)
53 struct rthash *rh;
54 struct rt_entry *rt;
55 boolean_t timetomulticast = _B_FALSE;
56 int i;
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.
67 if (alarmtime == 0) {
68 supplyinterval = GET_RANDOM(MIN_SUPPLY_TIME, MAX_SUPPLY_TIME);
69 iftime = 0;
70 mtime = supplyinterval;
71 alarmtime = supplyinterval;
72 (void) alarm(alarmtime);
73 return;
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.
80 mintime = INT_MAX;
81 (void) sighold(SIGHUP);
82 (void) sighold(SIGUSR1);
83 (void) sighold(SIGUSR2);
85 iftime += alarmtime;
86 if (iftime >= CHECK_INTERVAL) {
87 initifs();
88 iftime = 0;
90 mintime = min(mintime, CHECK_INTERVAL - iftime);
92 mtime += alarmtime;
93 if (mtime >= supplyinterval) {
94 if (supplier)
95 timetomulticast = _B_TRUE;
96 mtime = 0;
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)
103 continue;
105 for (rh = net_hashes[i];
106 rh < &net_hashes[i][ROUTEHASHSIZ]; rh++) {
107 for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
108 rt = rt->rt_forw) {
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)
116 continue;
117 rt->rt_timer += alarmtime;
118 if (rt->rt_timer >= GARBAGE_TIME) {
119 rt = rt->rt_back;
120 rtdelete(rt->rt_forw);
121 continue;
123 if (rt->rt_timer >= EXPIRE_TIME) {
124 rtdown(rt);
125 mintime = min(mintime,
126 GARBAGE_TIME - rt->rt_timer);
127 } else {
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);
138 lastmcast = now;
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.
150 alarmtime = mintime;
151 (void) alarm(alarmtime);
155 * On SIGTERM, let everyone know we're going away.
157 void
158 term(void)
160 struct rthash *rh;
161 struct rt_entry *rt;
162 int i;
164 if (!supplier)
165 exit(EXIT_SUCCESS);
166 for (i = IPV6_ABITS; i >= 0; i--) {
167 if (net_hashes[i] == NULL)
168 continue;
170 for (rh = net_hashes[i]; rh < &net_hashes[i][ROUTEHASHSIZ];
171 rh++) {
172 for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
173 rt = rt->rt_forw) {
174 rt->rt_metric = HOPCNT_INFINITY;
178 supplyall(&allrouters, 0, NULL, _B_TRUE);
179 (void) unlink(PATH_PID);
180 exit(EXIT_SUCCESS);