add Berkeley specific copyright notice
[unix-history] / usr / src / sbin / XNSrouted / timer.c
CommitLineData
4a10c08d 1/*
3565c602
KB
2 * Copyright (c) 1985 The Regents of the University of California.
3 * All rights reserved.
4a10c08d 4 *
3565c602
KB
5 * This file includes significant work done at Cornell University by
6 * Bill Nesheim. That work included by permission.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the University of California, Berkeley. The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
4a10c08d
KS
19 */
20
5474cc46 21#ifndef lint
3565c602
KB
22static char sccsid[] = "@(#)timer.c 5.5 (Berkeley) %G%";
23#endif /* not lint */
5474cc46
KS
24
25/*
26 * Routing Table Management Daemon
27 */
28#include "defs.h"
29
30int timeval = -TIMER_RATE;
31
32/*
33 * Timer routine. Performs routing information supply
34 * duties and manages timers on routing table entries.
35 */
36timer()
37{
38 register struct rthash *rh;
39 register struct rt_entry *rt;
40 struct rthash *base = hosthash;
41 int doinghost = 1, timetobroadcast;
42
43 timeval += TIMER_RATE;
44 if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
45 ifinit();
46 timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
47again:
48 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
49 rt = rh->rt_forw;
50 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
51 /*
52 * We don't advance time on a routing entry for
53 * a passive gateway or that for our only interface.
54 * The latter is excused because we don't act as
55 * a routing information supplier and hence would
56 * time it out. This is fair as if it's down
57 * we're cut off from the world anyway and it's
58 * not likely we'll grow any new hardware in
59 * the mean time.
60 */
61 if (!(rt->rt_state & RTS_PASSIVE) &&
62 (supplier || !(rt->rt_state & RTS_INTERFACE)))
63 rt->rt_timer += TIMER_RATE;
64 if (rt->rt_timer >= EXPIRE_TIME)
65 rt->rt_metric = HOPCNT_INFINITY;
66 if (rt->rt_timer >= GARBAGE_TIME) {
67 rt = rt->rt_back;
68 /* Perhaps we should send a REQUEST for this route? */
69 rtdelete(rt->rt_forw);
70 continue;
71 }
72 if (rt->rt_state & RTS_CHANGED) {
73 rt->rt_state &= ~RTS_CHANGED;
74 /* don't send extraneous packets */
75 if (!supplier || timetobroadcast)
76 continue;
77 msg->rip_cmd = htons(RIPCMD_RESPONSE);
84f93e8f
KS
78 msg->rip_nets[0].rip_dst =
79 (satons_addr(rt->rt_dst)).x_net;
5474cc46
KS
80 msg->rip_nets[0].rip_metric =
81 htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
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}
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}