summaryrefslogtreecommitdiffstats
path: root/sys/netatm/uni/uniarp_timer.c
blob: 0c2ea88af37510dc070f8ef0885d125c367379c0 (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
 *
 * ===================================
 * 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.
 *
 *	@(#) $FreeBSD$
 *
 */

/*
 * ATM Forum UNI Support
 * ---------------------
 *
 * UNI ATMARP support (RFC1577) - Timer processing
 *
 */

#include <netatm/kern_include.h>

#include <netatm/ipatm/ipatm_var.h>
#include <netatm/ipatm/ipatm_serv.h>
#include <netatm/uni/uniip_var.h>

#ifndef lint
__RCSID("@(#) $FreeBSD$");
#endif


/*
 * Local functions
 */
static void	uniarp_svc_oldage __P((struct uniarp *));
static void	uniarp_pvc_oldage __P((struct uniarp *));


/*
 * Process a UNI ATMARP entry timeout
 * 
 * Called when a previously scheduled uniarp control block timer expires.
 *
 * Called at splnet.
 *
 * Arguments:
 *	tip	pointer to uniarp timer control block
 *
 * Returns:
 *	none
 *
 */
void
uniarp_timeout(tip)
	struct atm_time	*tip;
{
	struct uniip	*uip;
	struct uniarp	*uap;
	struct ipvcc	*ivp;


	/*
	 * Back-off to uniarp control block
	 */
	uap = (struct uniarp *)
			((caddr_t)tip - (int)(&((struct uniarp *)0)->ua_time));
	uip = uap->ua_intf;


	/*
	 * Do we know the IP address for this entry yet??
	 */
	if (uap->ua_dstip.s_addr == 0) {

		/*
		 * No, then send another InATMARP_REQ on each active VCC
		 * associated with this entry to solicit the peer's identity.
		 */
		for (ivp = uap->ua_ivp; ivp; ivp = ivp->iv_arpnext) {
			if (ivp->iv_state != IPVCC_ACTIVE)
				continue;
			(void) uniarp_inarp_req(uip, &uap->ua_dstatm, 
				&uap->ua_dstatmsub, ivp);
		}

		/*
		 * Restart retry timer
		 */
		UNIARP_TIMER(uap, UNIARP_ARP_RETRY);
	} else {
		/*
		 * Yes, then we're trying to find the ATM address for this
		 * IP address - so send another ATMARP_REQ to the arpserver
		 * (if it's up at the moment)
		 */
		if (uip->uip_arpstate == UIAS_CLIENT_ACTIVE)
			(void) uniarp_arp_req(uip, &uap->ua_dstip);

		/*
		 * Restart retry timer
		 */
		UNIARP_TIMER(uap, UNIARP_ARP_RETRY);
	}

	return;
}


/*
 * Process an UNI ARP SVC entry aging timer expiration
 * 
 * This function is called when an SVC arp entry's aging timer has expired.
 *
 * Called at splnet().
 *
 * Arguments:
 *	uap	pointer to atmarp table entry
 *
 * Returns:
 *	none
 *
 */
static void
uniarp_svc_oldage(uap)
	struct uniarp	*uap;
{
	struct ipvcc	*ivp, *inext;
	struct uniip	*uip = uap->ua_intf;


	/*
	 * Permanent (manually installed) entries are never aged
	 */
	if (uap->ua_origin >= UAO_PERM)
		return;

	/*
	 * If entry is valid and we're out of retrys, tell
	 * IP/ATM that the SVCs can't be used
	 */
	if ((uap->ua_flags & UAF_VALID) && (uap->ua_retry-- == 0)) {
		uap->ua_flags |= UAF_LOCKED;
		for (ivp = uap->ua_ivp; ivp; ivp = inext) {
			inext = ivp->iv_arpnext;
			(*ivp->iv_ipnif->inf_arpnotify)(ivp, MAP_INVALID);
		}
		uap->ua_flags &= ~(UAF_LOCKED | UAF_VALID);
		uap->ua_origin = 0;

		/*
		 * Delete and free an unused entry
		 */
		if (uap->ua_ivp == NULL) {
			UNIARP_CANCEL(uap);
			UNIARP_DELETE(uap);
			atm_free((caddr_t)uap);
			return;
		}
	}

	/*
	 * We want to try and refresh this entry but we don't want
	 * to keep unused entries laying around forever.
	 */
	if (uap->ua_ivp || (uap->ua_flags & UAF_USED)) {
		if (uip->uip_arpstate == UIAS_CLIENT_ACTIVE) {
			/*
			 * If we are a client (and the server VCC is active),
			 * then we'll ask the server for a refresh
			 */ 
			(void) uniarp_arp_req(uip, &uap->ua_dstip);
		} else {
			/*
			 * Otherwise, solicit the each active VCC peer with 
			 * an Inverse ATMARP
			 */
			for (ivp = uap->ua_ivp; ivp; ivp = ivp->iv_arpnext) {
				if (ivp->iv_state != IPVCC_ACTIVE)
					continue;
				(void) uniarp_inarp_req(uip, &uap->ua_dstatm,
					&uap->ua_dstatmsub, ivp);
			}
		}
	}

	/*
	 * Reset timeout
	 */
	if (uap->ua_flags & UAF_VALID)
		uap->ua_aging = UNIARP_RETRY_AGE;
	else
		uap->ua_aging = UNIARP_REVALID_AGE;

	return;
}


/*
 * Process an UNI ARP PVC entry aging timer expiration
 * 
 * This function is called when a PVC arp entry's aging timer has expired.
 *
 * Called at splnet().
 *
 * Arguments:
 *	uap	pointer to atmarp table entry
 *
 * Returns:
 *	none
 *
 */
static void
uniarp_pvc_oldage(uap)
	struct uniarp	*uap;
{
	struct ipvcc	*ivp = uap->ua_ivp;

	/*
	 * If entry is valid and we're out of retrys, tell
	 * IP/ATM that PVC can't be used
	 */
	if ((uap->ua_flags & UAF_VALID) && (uap->ua_retry-- == 0)) {
		(*ivp->iv_ipnif->inf_arpnotify)(ivp, MAP_INVALID);
		uap->ua_flags &= ~UAF_VALID;
	}

	/*
	 * Solicit peer with Inverse ATMARP
	 */
	(void) uniarp_inarp_req(uap->ua_intf, &uap->ua_dstatm,
			&uap->ua_dstatmsub, ivp);

	/*
	 * Reset timeout
	 */
	if (uap->ua_flags & UAF_VALID)
		uap->ua_aging = UNIARP_RETRY_AGE;
	else
		uap->ua_aging = UNIARP_REVALID_AGE;

	return;
}


/*
 * Process a UNI ARP aging timer tick
 * 
 * This function is called every UNIARP_AGING seconds, in order to age
 * all the arp table entries.  If an entry's timer is expired, then the
 * uniarp old-age timeout function will be called for that entry.
 *
 * Called at splnet.
 *
 * Arguments:
 *	tip	pointer to uniarp aging timer control block
 *
 * Returns:
 *	none
 *
 */
void
uniarp_aging(tip)
	struct atm_time	*tip;
{
	struct uniarp	*uap, *unext;
	int		i;


	/*
	 * Schedule next timeout
	 */
	atm_timeout(&uniarp_timer, UNIARP_AGING, uniarp_aging);

	/*
	 * Run through arp table bumping each entry's aging timer.
	 * If an expired timer is found, process that entry.
	 */
	for (i = 0; i < UNIARP_HASHSIZ; i++) {
		for (uap = uniarp_arptab[i]; uap; uap = unext) {
			unext = uap->ua_next;

			if (uap->ua_aging && --uap->ua_aging == 0)
				uniarp_svc_oldage(uap);
		}
	}

	/*
	 * Check out PVC aging timers too
	 */
	for (uap = uniarp_pvctab; uap; uap = unext) {
		unext = uap->ua_next;

		if (uap->ua_aging && --uap->ua_aging == 0)
			uniarp_pvc_oldage(uap);
	}

	/*
	 * Only fully resolved SVC entries need aging, so there's no need
	 * to examine the 'no map' table
	 */
}

OpenPOWER on IntegriCloud