minor fixes
[unix-history] / usr / src / sbin / routed / timer.c
CommitLineData
5ff67f98
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
5919db1b 7#ifndef lint
88709531 8static char sccsid[] = "@(#)timer.c 5.4 (Berkeley) %G%";
5ff67f98 9#endif not lint
5919db1b
SL
10
11/*
12 * Routing Table Management Daemon
13 */
7fe7fe74 14#include "defs.h"
5919db1b
SL
15
16int timeval = -TIMER_RATE;
17
18/*
19 * Timer routine. Performs routing information supply
20 * duties and manages timers on routing table entries.
21 */
22timer()
23{
24 register struct rthash *rh;
25 register struct rt_entry *rt;
26 struct rthash *base = hosthash;
27 int doinghost = 1, timetobroadcast;
604bfd52 28 extern int externalinterfaces;
5919db1b
SL
29
30 timeval += TIMER_RATE;
31 if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
32 ifinit();
33 timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
34again:
35 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
36 rt = rh->rt_forw;
37 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
38 /*
39 * We don't advance time on a routing entry for
4ff053a6
MK
40 * a passive gateway, or any interface if we're
41 * not acting as supplier.
5919db1b
SL
42 */
43 if (!(rt->rt_state & RTS_PASSIVE) &&
4ff053a6 44 (supplier || !(rt->rt_state & RTS_INTERFACE)))
5919db1b 45 rt->rt_timer += TIMER_RATE;
5919db1b
SL
46 if (rt->rt_timer >= GARBAGE_TIME) {
47 rt = rt->rt_back;
48 rtdelete(rt->rt_forw);
49 continue;
50 }
88709531
MK
51 if (rt->rt_timer >= EXPIRE_TIME)
52 rtchange(rt, &rt->rt_router, HOPCNT_INFINITY);
5919db1b
SL
53 if (rt->rt_state & RTS_CHANGED) {
54 rt->rt_state &= ~RTS_CHANGED;
55 /* don't send extraneous packets */
56 if (!supplier || timetobroadcast)
57 continue;
58 msg->rip_cmd = RIPCMD_RESPONSE;
55d340a4 59 msg->rip_vers = RIPVERSION;
5919db1b 60 msg->rip_nets[0].rip_dst = rt->rt_dst;
55d340a4
SL
61 msg->rip_nets[0].rip_dst.sa_family =
62 htons(msg->rip_nets[0].rip_dst.sa_family);
63 msg->rip_nets[0].rip_metric =
88709531
MK
64 htonl(min(rt->rt_metric + rt->rt_ifmetric,
65 HOPCNT_INFINITY));
5919db1b
SL
66 toall(sendmsg);
67 }
68 }
69 }
70 if (doinghost) {
71 doinghost = 0;
72 base = nethash;
73 goto again;
74 }
75 if (timetobroadcast)
76 toall(supply);
77 alarm(TIMER_RATE);
78}
b7e4f8be
MK
79
80/*
81 * On hangup, let everyone know we're going away.
82 */
83hup()
84{
85 register struct rthash *rh;
86 register struct rt_entry *rt;
87 struct rthash *base = hosthash;
88 int doinghost = 1;
89
90 if (supplier) {
91again:
92 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
93 rt = rh->rt_forw;
94 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
95 rt->rt_metric = HOPCNT_INFINITY;
96 }
97 if (doinghost) {
98 doinghost = 0;
99 base = nethash;
100 goto again;
101 }
102 toall(supply);
103 }
104 exit(1);
105}