install correct aliases file
[unix-history] / usr / src / sbin / routed / timer.c
CommitLineData
5ff67f98 1/*
f6048f23 2 * Copyright (c) 1983, 1988 Regents of the University of California.
0eb85d71
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
b8c620d6
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
5ff67f98
DF
16 */
17
5919db1b 18#ifndef lint
b8c620d6 19static char sccsid[] = "@(#)timer.c 5.7 (Berkeley) %G%";
0eb85d71 20#endif /* not lint */
5919db1b
SL
21
22/*
23 * Routing Table Management Daemon
24 */
7fe7fe74 25#include "defs.h"
5919db1b
SL
26
27int timeval = -TIMER_RATE;
28
29/*
30 * Timer routine. Performs routing information supply
31 * duties and manages timers on routing table entries.
32 */
33timer()
34{
35 register struct rthash *rh;
36 register struct rt_entry *rt;
37 struct rthash *base = hosthash;
f6048f23 38 int doinghost = 1, timetobroadcast, changes = 0;
604bfd52 39 extern int externalinterfaces;
f6048f23 40 time_t now;
5919db1b
SL
41
42 timeval += TIMER_RATE;
43 if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
44 ifinit();
45 timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
46again:
47 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
48 rt = rh->rt_forw;
49 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
50 /*
51 * We don't advance time on a routing entry for
4ff053a6
MK
52 * a passive gateway, or any interface if we're
53 * not acting as supplier.
5919db1b
SL
54 */
55 if (!(rt->rt_state & RTS_PASSIVE) &&
4ff053a6 56 (supplier || !(rt->rt_state & RTS_INTERFACE)))
5919db1b 57 rt->rt_timer += TIMER_RATE;
5919db1b
SL
58 if (rt->rt_timer >= GARBAGE_TIME) {
59 rt = rt->rt_back;
60 rtdelete(rt->rt_forw);
61 continue;
62 }
f6048f23
MK
63 if (rt->rt_timer >= EXPIRE_TIME) {
64 if (traceactions && changes++ == 0) {
65 (void) time(&now);
66 curtime = ctime(&now);
67 }
88709531 68 rtchange(rt, &rt->rt_router, HOPCNT_INFINITY);
f6048f23 69 }
5919db1b
SL
70 if (rt->rt_state & RTS_CHANGED) {
71 rt->rt_state &= ~RTS_CHANGED;
72 /* don't send extraneous packets */
73 if (!supplier || timetobroadcast)
74 continue;
75 msg->rip_cmd = RIPCMD_RESPONSE;
55d340a4 76 msg->rip_vers = RIPVERSION;
5919db1b 77 msg->rip_nets[0].rip_dst = rt->rt_dst;
55d340a4
SL
78 msg->rip_nets[0].rip_dst.sa_family =
79 htons(msg->rip_nets[0].rip_dst.sa_family);
80 msg->rip_nets[0].rip_metric =
f6048f23 81 htonl(min(rt->rt_metric, HOPCNT_INFINITY));
5919db1b
SL
82 toall(sendmsg);
83 }
84 }
85 }
86 if (doinghost) {
87 doinghost = 0;
88 base = nethash;
89 goto again;
90 }
91 if (timetobroadcast)
92 toall(supply);
93 alarm(TIMER_RATE);
94}
b7e4f8be
MK
95
96/*
97 * On hangup, let everyone know we're going away.
98 */
99hup()
100{
101 register struct rthash *rh;
102 register struct rt_entry *rt;
103 struct rthash *base = hosthash;
104 int doinghost = 1;
105
106 if (supplier) {
107again:
108 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
109 rt = rh->rt_forw;
110 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
111 rt->rt_metric = HOPCNT_INFINITY;
112 }
113 if (doinghost) {
114 doinghost = 0;
115 base = nethash;
116 goto again;
117 }
118 toall(supply);
119 }
120 exit(1);
121}