summaryrefslogtreecommitdiffstats
path: root/usr.sbin/atm/atmarpd/atmarp_timer.c
blob: cee01eb91cf07141199db92249cf853e98607ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 *
 * ===================================
 * HARP  |  Host ATM Research Platform
 * ===================================
 *
 *
 * This Host ATM Research Platform ("HARP") file (the "Software") is
 * made available by Network Computing Services, Inc. ("NetworkCS")
 * "AS IS".  NetworkCS does not provide maintenance, improvements or
 * support of any kind.
 *
 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
 * In no event shall NetworkCS be responsible for any damages, including
 * but not limited to consequential damages, arising from or relating to
 * any use of the Software or related support.
 *
 * Copyright 1994-1998 Network Computing Services, Inc.
 *
 * Copies of this Software may be made, however, the above copyright
 * notice must be reproduced on all copies.
 *
 *	@(#) $Id: atmarp_timer.c,v 1.1 1998/09/15 08:23:15 phk Exp $
 *
 */

/*
 * Server Cache Synchronization Protocol (SCSP) Support
 * ----------------------------------------------------
 *
 * SCSP-ATMARP server interface: timer routines
 *
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netatm/port.h>
#include <netatm/queue.h>
#include <netatm/atm.h>
#include <netatm/atm_if.h>
#include <netatm/atm_sap.h>
#include <netatm/atm_sys.h>
#include <netatm/atm_ioctl.h>
 
#include <errno.h>
#include <libatm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

#include "../scspd/scsp_msg.h"
#include "../scspd/scsp_if.h"
#include "../scspd/scsp_var.h"
#include "atmarp_var.h"

#ifndef lint
__RCSID("@(#) $Id: atmarp_timer.c,v 1.1 1998/09/15 08:23:15 phk Exp $");
#endif


/*
 * Cache update timeout processing
 *
 * When the cache update timer fires, we read the cache from the
 * kernel, update the internal cache, and restart the timer.
 *
 * Arguments:
 *	tp	pointer to a HARP timer block
 *
 * Returns:
 *	None
 *
 */
void
atmarp_cache_timeout(tp)
	Harp_timer	*tp;
{
	Atmarp_intf	*aip;

	/*
	 * Verify the status of all configured interfaces
	 */
	for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
		if (atmarp_if_ready(aip)) {
			/*
			 * The interface is up but we don't have
			 * a connection to SCSP--make a connection
			 */
			if (aip->ai_state == AI_STATE_NULL)
				(void)atmarp_scsp_connect(aip);
		} else {
			/*
			 * The interface is down--disconnect from SCSP
			 */
			if (aip->ai_state != AI_STATE_NULL)
				(void)atmarp_scsp_disconnect(aip);
		}
	}

	/*
	 * Read the cache from the kernel
	 */
	atmarp_get_updated_cache();

	/*
	 * Restart the cache update timer
	 */
	HARP_TIMER(tp, ATMARP_CACHE_INTERVAL, atmarp_cache_timeout);
}


/*
 * Permanent cache entry timer processing
 *
 * Permanent cache entries (entries that are administratively added
 * and the entry for the server itself) don't ever get refreshed, so
 * we broadcast updates for them every 10 minutes so they won't get
 * deleted from the remote servers' caches
 *
 * Arguments:
 *	tp	pointer to a HARP timer block
 *
 * Returns:
 *	None
 *
 */
void
atmarp_perm_timeout(tp)
	Harp_timer	*tp;
{
	int		i, rc;
	Atmarp_intf	*aip;
	Atmarp		*aap;

	/*
	 * Loop through all interfaces
	 */
	for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
		/*
		 * Loop through the interface's cache
		 */
		for (i = 0; i < ATMARP_HASHSIZ; i++) {
			for (aap = aip->ai_arptbl[i]; aap;
					aap = aap->aa_next) {
				/*
				 * Find and update permanent entries
				 */
				if ((aap->aa_flags & (AAF_PERM |
						AAF_SERVER)) != 0) {
					aap->aa_seq++;
					rc = atmarp_scsp_update(aap,
						SCSP_ASTATE_UPD);
				}
			}
		}
	}

	/*
	 * Restart the permanent cache entry timer
	 */
	HARP_TIMER(tp, ATMARP_PERM_INTERVAL, atmarp_perm_timeout);
}


/*
 * Keepalive timeout processing
 *
 * When the keepalive timer fires, we send a NOP to SCSP.  This
 * will help us detect a broken connection.
 *
 * Arguments:
 *	tp	pointer to a HARP timer block
 *
 * Returns:
 *	None
 *
 */
void
atmarp_keepalive_timeout(tp)
	Harp_timer	*tp;
{
	Atmarp_intf	*aip;
	Scsp_if_msg	*msg;

	/*
	 * Back off to start of DCS entry
	 */
	aip = (Atmarp_intf *) ((caddr_t)tp -
			(int)(&((Atmarp_intf *)0)->ai_keepalive_t));

	/*
	 * Get a message buffer
	 */
	msg = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
	if (!msg) {
	}
	UM_ZERO(msg, sizeof(Scsp_if_msg));

	/*
	 * Build a NOP message
	 */
	msg->si_type = SCSP_NOP_REQ;
	msg->si_proto = SCSP_PROTO_ATMARP;
	msg->si_len = sizeof(Scsp_if_msg_hdr);

	/*
	 * Send the message to SCSP
	 */
	(void)atmarp_scsp_out(aip, (char *)msg, msg->si_len);
	UM_FREE(msg);

	/*
	 * Restart the keepalive timer
	 */
	HARP_TIMER(&aip->ai_keepalive_t, ATMARP_KEEPALIVE_INTERVAL,
			atmarp_keepalive_timeout);
}
OpenPOWER on IntegriCloud