summaryrefslogtreecommitdiffstats
path: root/usr.sbin/atm/atmarpd/atmarp_scsp.c
blob: 0f842e4679444c391d79e824caea4c246f1eb794 (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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/*
 *
 * ===================================
 * 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$
 *
 */

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

#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 <netatm/uni/uniip_var.h>
 
#include <errno.h>
#include <fcntl.h>
#include <libatm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>

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

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


/*
 * Send the cache for a LIS to SCSP
 *
 *
 * Arguments:
 *	aip	pointer to interface block
 *
 * Returns:
 *	0	cache sent to SCSP OK
 *	errno	reason for failure
 *
 */
int
atmarp_scsp_cache(aip, msg)
	Atmarp_intf	*aip;
	Scsp_if_msg	*msg;
{
	int		i, len, rc = 0;
	Atmarp		*aap;
	Scsp_if_msg	*smp = (Scsp_if_msg *)0;
	Scsp_atmarp_msg	*sap;

	/*
	 * Figure out how big the message needs to be
	 */
	len = sizeof(Scsp_if_msg_hdr);
	for (i = 0; i < ATMARP_HASHSIZ; i++) {
		for (aap = aip->ai_arptbl[i]; aap; aap = aap->aa_next) {
			len += sizeof(Scsp_atmarp_msg);
		}
	}

	/*
	 * Get memory for the cache message
	 */
	smp = (Scsp_if_msg *)UM_ALLOC(len);
	if (!smp) {
		atmarp_mem_err("atmarp_scsp_cache: len");
	}
	UM_ZERO(smp, len);

	/*
	 * Set header fields in SCSP message
	 */
	smp->si_type = SCSP_CACHE_RSP;
	smp->si_proto = SCSP_PROTO_ATMARP;
	smp->si_len = len;
	smp->si_tok = msg->si_tok;

	/*
	 * Loop through the cache, adding each entry to the SCSP
	 * Cache Response message
	 */
	sap = &smp->si_atmarp;
	for (i = 0; i < ATMARP_HASHSIZ; i++) {
		for (aap = aip->ai_arptbl[i]; aap; aap = aap->aa_next) {
			sap->sa_state = SCSP_ASTATE_NEW;
			sap->sa_cpa = aap->aa_dstip;
			ATM_ADDR_COPY(&aap->aa_dstatm, &sap->sa_cha);
			ATM_ADDR_COPY(&aap->aa_dstatmsub, &sap->sa_csa);
			sap->sa_key = aap->aa_key;
			sap->sa_oid = aap->aa_oid;
			sap->sa_seq = aap->aa_seq;
			sap++;
		}
	}

	/*
	 * Send the message to SCSP
	 */
	rc = atmarp_scsp_out(aip, (char *)smp, len);

	/*
	 * Free the message
	 */
	if (smp)
		UM_FREE(smp);

	return(rc);
}


/*
 * Answer a reqeust for information about a cache entry
 *
 * Arguments:
 *	aap	pointer to entry
 *	state	entry's new state
 *
 * Returns:
 *	0	success
 *	errno	reason for failure
 *
 */
int
atmarp_scsp_solicit(aip, smp)
	Atmarp_intf	*aip;
	Scsp_if_msg	*smp;
{
	int		i, rc = 0;
	Atmarp		*aap;
	Scsp_if_msg	*rsp = (Scsp_if_msg *)0;

	/*
	 * Search the interface's ATMARP cache for an entry with
	 * the specified cache key and origin ID
	 */
	for (i = 0; i < ATMARP_HASHSIZ; i++) {
		for (aap = aip->ai_arptbl[i]; aap; aap = aap->aa_next) {
			if (KEY_EQUAL(&aap->aa_key,
					&smp->si_sum.ss_key) &&
					OID_EQUAL(&aap->aa_oid,
					&smp->si_sum.ss_oid))
				break;
		}
		if (aap)
			break;
	}

	/*
	 * Get storage for a Solicit Response
	 */
	rsp = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
	if (!rsp) {
		atmarp_mem_err("atmarp_scsp_solicit: sizeof(Scsp_if_msg)");
	}
	UM_ZERO(rsp, sizeof(Scsp_if_msg));

	/*
	 * Fill out the Solicit Rsp
	 */
	rsp->si_type = SCSP_SOLICIT_RSP;
	rsp->si_proto = smp->si_proto;
	rsp->si_tok = smp->si_tok;

	if (aap) {
		/*
		 * Copy fields from the ATMARP entry to the SCSP
		 * Update Request message
		 */
		rsp->si_rc = SCSP_RSP_OK;
		rsp->si_len = sizeof(Scsp_if_msg_hdr) +
				sizeof(Scsp_atmarp_msg);
		rsp->si_atmarp.sa_state = SCSP_ASTATE_UPD;
		rsp->si_atmarp.sa_cpa = aap->aa_dstip;
		ATM_ADDR_COPY(&aap->aa_dstatm, &rsp->si_atmarp.sa_cha);
		ATM_ADDR_COPY(&aap->aa_dstatmsub, &rsp->si_atmarp.sa_csa);
		rsp->si_atmarp.sa_key = aap->aa_key;
		rsp->si_atmarp.sa_oid = aap->aa_oid;
		rsp->si_atmarp.sa_seq = aap->aa_seq;
	} else {
		/*
		 * Entry not found--set return code
		 */
		rsp->si_rc = SCSP_RSP_NOT_FOUND;
		rsp->si_len = smp->si_len;
		rsp->si_sum = smp->si_sum;
	}

	/*
	 * Send the message to SCSP
	 */
	rc = atmarp_scsp_out(aip, (char *)rsp, rsp->si_len);
	UM_FREE(rsp);

	return(rc);
}


/*
 * Send a cache update to SCSP
 *
 * Arguments:
 *	aap	pointer to entry
 *	state	entry's new state
 *
 * Returns:
 *	0	success
 *	errno	reason for failure
 *
 */
int
atmarp_scsp_update(aap, state)
	Atmarp		*aap;
	int		state;
{
	int		rc = 0;
	Atmarp_intf	*aip = aap->aa_intf;
	Scsp_if_msg	*smp = (Scsp_if_msg *)0;

	/*
	 * Make sure the connection to SCSP is active
	 */
	if (aip->ai_state == AI_STATE_NULL) {
		return(0);
	}

	/*
	 * Get memory for the cache message
	 */
	smp = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
	if (!smp) {
		atmarp_mem_err("atmarp_scsp_update: sizeof(Scsp_if_msg)");
	}
	UM_ZERO(smp, sizeof(Scsp_if_msg));

	/*
	 * Set header fields in SCSP message
	 */
	smp->si_type = SCSP_UPDATE_REQ;
	smp->si_proto = SCSP_PROTO_ATMARP;
	smp->si_len = sizeof(Scsp_if_msg_hdr) + sizeof(Scsp_atmarp_msg);

	/*
	 * Copy fields from the ATMARP entry to the SCSP
	 * Update Request message
	 */
	smp->si_atmarp.sa_state = state;
	smp->si_atmarp.sa_cpa = aap->aa_dstip;
	ATM_ADDR_COPY(&aap->aa_dstatm, &smp->si_atmarp.sa_cha);
	ATM_ADDR_COPY(&aap->aa_dstatmsub, &smp->si_atmarp.sa_csa);
	smp->si_atmarp.sa_key = aap->aa_key;
	smp->si_atmarp.sa_oid = aap->aa_oid;
	smp->si_atmarp.sa_seq = aap->aa_seq;

	/*
	 * Send the message to SCSP
	 */
	rc = atmarp_scsp_out(aap->aa_intf, (char *)smp, smp->si_len);

	UM_FREE(smp);
	return(rc);
}


/*
 * Respond to a Cache Update Indication from SCSP
 *
 *
 * Arguments:
 *	aip	pointer to interface control block
 *	smp	pointer to message from SCSP
 *
 * Returns:
 *	0	Message processed OK
 *	errno	Reason for failure
 *
 */
int
atmarp_scsp_update_in(aip, smp)
	Atmarp_intf	*aip;
	Scsp_if_msg	*smp;
{
	int	accept, rc;
	Atmarp	*aap;

	/*
	 * Look up the entry
	 */
	ATMARP_LOOKUP(aip, smp->si_atmarp.sa_cpa.s_addr, aap);

	/*
	 * Whether we accept the request depends on whether we
	 * already have an entry for it
	 */
	 if (!aap) {
		/*
		 * We don't have this entry--accept it
		 */
		accept = 1;
	} else {
		/*
		 * We do have an entry for this host--check the
		 * origin ID
		 */
		if (bcmp(&aip->ai_ip_addr.s_addr,
				smp->si_atmarp.sa_oid.id,
				SCSP_ATMARP_ID_LEN) == 0) {
			/*
			 * The received entry originated with us--
			 * reject it
			 */
			accept = 0;
		} else if (bcmp(&aip->ai_ip_addr.s_addr,
				aap->aa_oid.id,
				SCSP_ATMARP_ID_LEN) == 0) {
			/*
			 * We originated the entry we currently have--
			 * only accept the new one if SCSP has higher
			 * priority than the existing entry
			 */
			accept = aap->aa_origin < UAO_SCSP;
		} else {
			/*
			 * Accept the entry if it is more up-to-date
			 * than the existing entry
			 */
			accept = KEY_EQUAL(&aap->aa_key,
					&smp->si_atmarp.sa_key) &&
				OID_EQUAL(&aap->aa_oid,
					&smp->si_atmarp.sa_oid) &&
				(aap->aa_seq < smp->si_atmarp.sa_seq);
		}
	}

	/*
	 * Add the entry to the cache, if appropriate
	 */
	if (accept) {
		if (!aap) {
			/*
			 * Copy info from SCSP to a new cache entry
			 */
			aap = (Atmarp *)UM_ALLOC(sizeof(Atmarp));
			if (!aap)
				atmarp_mem_err("atmarp_scsp_update_in: sizeof(Atmarp)");
			UM_ZERO(aap, sizeof(Atmarp));

			aap->aa_dstip = smp->si_atmarp.sa_cpa;
			aap->aa_dstatm = smp->si_atmarp.sa_cha;
			aap->aa_dstatmsub = smp->si_atmarp.sa_csa;
			aap->aa_key = smp->si_atmarp.sa_key;
			aap->aa_oid = smp->si_atmarp.sa_oid;
			aap->aa_seq = smp->si_atmarp.sa_seq;
			aap->aa_intf = aip;
			aap->aa_origin = UAO_SCSP;

			/*
			 * Add the new entry to our cache
			 */
			ATMARP_ADD(aip, aap);
		} else {
			/*
			 * Update the existing entry
			 */
			aap->aa_dstip = smp->si_atmarp.sa_cpa;
			aap->aa_dstatm = smp->si_atmarp.sa_cha;
			aap->aa_dstatmsub = smp->si_atmarp.sa_csa;
			aap->aa_key = smp->si_atmarp.sa_key;
			aap->aa_oid = smp->si_atmarp.sa_oid;
			aap->aa_seq = smp->si_atmarp.sa_seq;
			aap->aa_origin = UAO_SCSP;
		}

		/*
		 * Send the updated entry to the kernel
		 */
		if (atmarp_update_kernel(aap) == 0)
			rc = SCSP_RSP_OK;
		else
			rc = SCSP_RSP_REJ;
	} else {
		rc = SCSP_RSP_REJ;
	}

	/*
	 * Turn the received message into a response
	 */
	smp->si_type = SCSP_UPDATE_RSP;
	smp->si_rc = rc;

	/*
	 * Send the message to SCSP
	 */
	rc = atmarp_scsp_out(aip, (char *)smp, smp->si_len);

	return(rc);
}


/*
 * Read and process a message from SCSP
 *
 *
 * Arguments:
 *	aip	interface for read
 *
 * Returns:
 *	0	success
 *	errno	reason for failure
 *
 */
int
atmarp_scsp_read(aip)
	Atmarp_intf	*aip;
{
	int		len, rc = 0;
	char		*buff = (char *)0;
	Scsp_if_msg	*smp;
	Scsp_if_msg_hdr	msg_hdr;

	/*
	 * Read the header of the message from SCSP
	 */
	len = read(aip->ai_scsp_sock, (char *)&msg_hdr,
			sizeof(msg_hdr));
	if (len == -1) {
		rc = errno;
		goto read_fail;
	} else if (len != sizeof(msg_hdr)) {
		rc = EMSGSIZE;
		goto read_fail;
	}

	/*
	 * Get a buffer that will hold the message
	 */
	buff = UM_ALLOC(msg_hdr.sh_len);
	if (!buff)
		atmarp_mem_err("atmarp_scsp_read: msg_hdr.sh_len");
	UM_COPY(&msg_hdr, buff, sizeof(msg_hdr));

	/*
	 * Read the rest of the message, if there is more than
	 * just a header
	 */
	len = msg_hdr.sh_len - sizeof(msg_hdr);
	if (len > 0) {
		len = read(aip->ai_scsp_sock, buff + sizeof(msg_hdr),
				len);
		if (len == -1) {
			rc = errno;
			goto read_fail;
		} else if (len != msg_hdr.sh_len - sizeof(msg_hdr)) {
			rc = EMSGSIZE;
			goto read_fail;
		}
	}

	/*
	 * Handle the message based on its type
	 */
	smp = (Scsp_if_msg *)buff;
	switch(smp->si_type) {
	case SCSP_CFG_RSP:
		if (smp->si_rc != SCSP_RSP_OK) {
			rc = EINVAL;
			goto read_fail;
		}
		break;
	case SCSP_CACHE_IND:
		rc = atmarp_scsp_cache(aip, smp);
		break;
	case SCSP_SOLICIT_IND:
		rc = atmarp_scsp_solicit(aip, smp);
		break;
	case SCSP_UPDATE_IND:
		rc = atmarp_scsp_update_in(aip, smp);
		break;
	case SCSP_UPDATE_RSP:
		/*
		 * Ignore Update Responses
		 */
		break;
	default:
		atmarp_log(LOG_ERR, "Unexpected SCSP message received");
		return(EOPNOTSUPP);
	}

	UM_FREE(buff);
	return(rc);

read_fail:
	if (buff) {
		UM_FREE(buff);
	}

	/*
	 * Error on socket to SCSP--close the socket and set the state
	 * so that we know to retry when the cache timer fires.
	 */
	atmarp_scsp_close(aip);

	return(rc);
}


/*
 * Send a message to SCSP
 *
 *
 * Arguments:
 *	aip	pointer to ATMARP interface to send message on
 *	buff	pointer to message buffer
 *	len	length of message
 *
 * Returns:
 *	0	message sent
 *	errno	reason for failure
 *
 */
int
atmarp_scsp_out(aip, buff, len)
	Atmarp_intf	*aip;
	char		*buff;
	int		len;
{
	int	rc;

	/*
	 * Send the message to SCSP
	 */
	rc = write(aip->ai_scsp_sock, buff, len);
	if (rc == len)
		return(0);

	/*
	 * Error on write--close the socket to SCSP, clean up and
	 * set the state so that we know to retry when the cache
	 * timer fires.
	 */
	atmarp_scsp_close(aip);

	/*
	 * Set the return code
	 */
	if (rc < 0) {
		rc = errno;
	} else {
		rc = EFAULT;
	}

	return(rc);
}


/*
 * Set up a socket and connect to SCSP
 *
 * Arguments:
 *	aip	pointer to interface block
 *
 * Returns:
 *	0	success, ai_scsp_sock is set
 *	errno	reason for failure
 *
 *
 */
int
atmarp_scsp_connect(aip)
	Atmarp_intf	*aip;
{
	int		len, rc, sd;
	char		*sn;
	Scsp_if_msg	cfg_msg;

	static struct sockaddr	local_addr = {
#if (defined(BSD) && (BSD >= 199103))
		sizeof(struct sockaddr),	/* sa_len */
#endif
		AF_UNIX,			/* sa_family */
		ATMARP_SOCK_PREFIX		/* sa_data */
	};
	static struct sockaddr	scsp_addr = {
#if (defined(BSD) && (BSD >= 199103))
		sizeof(struct sockaddr),	/* sa_len */
#endif
		AF_UNIX,			/* sa_family */
		SCSPD_SOCK_NAME			/* sa_data */
	};

	/*
	 * Construct a name for the socket
	 */
	strncpy(local_addr.sa_data, ATMARP_SOCK_PREFIX,
			sizeof(local_addr.sa_data));
	(void)strncat(local_addr.sa_data, aip->ai_intf,
			sizeof(local_addr.sa_data));
	sn = strdup(local_addr.sa_data);
	if (!sn)
		atmarp_mem_err("atmarp_scsp_connect: strdup");

	/*
	 * Clean up any old socket
	 */
	rc = unlink(sn);
	if (rc < 0 && errno != ENOENT)
		return(errno);

	/*
	 * Open a socket to SCSP
	 */
	sd = socket(PF_UNIX, SOCK_STREAM, 0);
	if (sd == -1) {
		UM_FREE(sn);
		return(errno);
	}
	if (sd > atmarp_max_socket) {
		atmarp_max_socket = sd;
	}

	/*
	 * Set non-blocking I/O
	 */
#ifdef sun
	rc = fcntl(sd, F_SETFL, FNBIO + FNDELAY);
#else
	rc = fcntl(sd, F_SETFL, O_NONBLOCK);
#endif
	if (rc == -1) {
		rc = errno;
		goto scsp_connect_fail;
	}

	/*
	 * Bind the local socket address
	 */
	rc = bind(sd, &local_addr, sizeof(local_addr));
	if (rc) {
		rc = errno;
		goto scsp_connect_fail;
	}

	/*
	 * Connect to SCSP
	 */
	rc = connect(sd, &scsp_addr, sizeof(scsp_addr));
	if (rc) {
		rc = errno;
		goto scsp_connect_fail;
	}

	/*
	 * Save socket information in interface control block
	 */
	aip->ai_scsp_sock = sd;
	aip->ai_scsp_sockname = sn;
	aip->ai_state = AI_STATE_UP;

	/*
	 * Send configuration information to SCSP
	 */
	UM_ZERO(&cfg_msg, sizeof(cfg_msg));
	cfg_msg.si_type = SCSP_CFG_REQ;
	cfg_msg.si_proto = SCSP_PROTO_ATMARP;
	strcpy(cfg_msg.si_cfg.atmarp_netif, aip->ai_intf);
	len =sizeof(Scsp_if_msg_hdr) + strlen(aip->ai_intf) + 1;
	cfg_msg.si_len = len;
	rc = atmarp_scsp_out(aip, (char *)&cfg_msg, len);
	if (rc) {
		return(rc);
	}

	return(0);

scsp_connect_fail:
	(void)close(sd);
	aip->ai_scsp_sock = -1;
	UM_FREE(sn);
	aip->ai_scsp_sockname = NULL;
	aip->ai_state = AI_STATE_NULL;
	return(rc);
}


/*
 * Close a socket connection to SCSP
 *
 * Arguments:
 *	aip	pointer to interface block for connection to be closed
 *
 * Returns:
 *	none
 *
 *
 */
void
atmarp_scsp_close(aip)
	Atmarp_intf	*aip;
{
	/*
	 * Close and unlink the SCSP socket
	 */
	(void)close(aip->ai_scsp_sock);
	aip->ai_scsp_sock = -1;
	(void)unlink(aip->ai_scsp_sockname);
	UM_FREE(aip->ai_scsp_sockname);
	aip->ai_scsp_sockname = NULL;

	aip->ai_state = AI_STATE_NULL;

	return;
}


/*
 * Disconnect an interface from SCSP
 *
 * Arguments:
 *	aip	pointer to interface block for connection to be closed
 *
 * Returns:
 *	0	success, ai_scsp_sock is set
 *	errno	reason for failure
 *
 *
 */
int
atmarp_scsp_disconnect(aip)
	Atmarp_intf	*aip;
{
	int	i;
	Atmarp	*aap;

	/*
	 * Close and unlink the SCSP socket
	 */
	atmarp_scsp_close(aip);

	/*
	 * Free the ATMARP cache associated with the interface
	 */
	for (i = 0; i < ATMARP_HASHSIZ; i++) {
		for (aap = aip->ai_arptbl[i]; aap; aap = aap->aa_next) {
			UM_FREE(aap);
		}
		aip->ai_arptbl[i] = (Atmarp *)0;
	}

	return(0);
}
OpenPOWER on IntegriCloud