2 * ===================================
3 * HARP | Host ATM Research Platform
4 * ===================================
7 * This Host ATM Research Platform ("HARP") file (the "Software") is
8 * made available by Network Computing Services, Inc. ("NetworkCS")
9 * "AS IS". NetworkCS does not provide maintenance, improvements or
10 * support of any kind.
12 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
13 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
14 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
15 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
16 * In no event shall NetworkCS be responsible for any damages, including
17 * but not limited to consequential damages, arising from or relating to
18 * any use of the Software or related support.
20 * Copyright 1994-1998 Network Computing Services, Inc.
22 * Copies of this Software may be made, however, the above copyright
23 * notice must be reproduced on all copies.
30 * ATM common socket protocol processing
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/malloc.h>
39 #include <sys/socket.h>
40 #include <sys/socketvar.h>
41 #include <sys/syslog.h>
43 #include <netatm/port.h>
44 #include <netatm/queue.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_sys.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_cm.h>
49 #include <netatm/atm_if.h>
50 #include <netatm/atm_sigmgr.h>
51 #include <netatm/atm_stack.h>
52 #include <netatm/atm_pcb.h>
53 #include <netatm/atm_var.h>
64 static uma_zone_t atm_pcb_zone;
66 static struct t_atm_cause atm_sock_cause = {
69 T_ATM_CAUSE_UNSPECIFIED_NORMAL,
77 atm_pcb_zone = uma_zcreate("atm pcb", sizeof(Atm_pcb), NULL, NULL,
78 NULL, NULL, UMA_ALIGN_PTR, 0);
79 if (atm_pcb_zone == NULL)
80 panic("atm_sock_init: unable to initialize atm_pcb_zone");
84 * Allocate resources for a new ATM socket
89 * so pointer to socket
90 * send socket send buffer maximum
91 * recv socket receive buffer maximum
95 * errno attach failed - reason indicated
99 atm_sock_attach(so, send, recv)
104 Atm_pcb *atp = sotoatmpcb(so);
108 * Make sure initialization has happened
114 * Make sure we're not already attached
120 * Reserve socket buffer space, if not already done
122 if ((so->so_snd.sb_hiwat == 0) || (so->so_rcv.sb_hiwat == 0)) {
123 err = soreserve(so, send, recv);
129 * Allocate and initialize our control block
131 atp = uma_zalloc(atm_pcb_zone, M_ZERO | M_NOWAIT);
135 atp->atp_socket = so;
136 so->so_pcb = (caddr_t)atp;
142 * Detach from socket and free resources
147 * so pointer to socket
150 * 0 detach successful
151 * errno detach failed - reason indicated
158 Atm_pcb *atp = sotoatmpcb(so);
161 * Make sure we're still attached
167 * Terminate any (possibly pending) connection
170 (void) atm_sock_disconnect(so);
174 * Break links and free control blocks
181 uma_zfree(atm_pcb_zone, atp);
188 * Bind local address to socket
193 * so pointer to socket
194 * addr pointer to protocol address
197 * 0 request processed
198 * errno error processing request - reason indicated
202 atm_sock_bind(so, addr)
204 struct sockaddr *addr;
206 Atm_pcb *atp = sotoatmpcb(so);
208 struct sockaddr_atm *satm;
209 struct t_atm_sap_addr *sapadr;
210 struct t_atm_sap_layer2 *sapl2;
211 struct t_atm_sap_layer3 *sapl3;
212 struct t_atm_sap_appl *sapapl;
215 * Make sure we're still attached
221 * Can't change local address once we've started connection process
223 if (atp->atp_conn != NULL)
224 return (EADDRNOTAVAIL);
227 * Validate requested local address
229 satm = (struct sockaddr_atm *)addr;
230 if (satm->satm_family != AF_ATM)
231 return (EAFNOSUPPORT);
233 sapadr = &satm->satm_addr.t_atm_sap_addr;
234 if (sapadr->SVE_tag_addr == T_ATM_PRESENT) {
235 if (sapadr->address_format == T_ATM_ENDSYS_ADDR) {
236 if (sapadr->SVE_tag_selector != T_ATM_PRESENT)
238 } else if (sapadr->address_format == T_ATM_E164_ADDR) {
239 if (sapadr->SVE_tag_selector != T_ATM_ABSENT)
243 } else if ((sapadr->SVE_tag_addr != T_ATM_ABSENT) &&
244 (sapadr->SVE_tag_addr != T_ATM_ANY))
246 if (sapadr->address_length > ATM_ADDR_LEN)
249 sapl2 = &satm->satm_addr.t_atm_sap_layer2;
250 if (sapl2->SVE_tag == T_ATM_PRESENT) {
251 if ((sapl2->ID_type != T_ATM_SIMPLE_ID) &&
252 (sapl2->ID_type != T_ATM_USER_ID))
254 } else if ((sapl2->SVE_tag != T_ATM_ABSENT) &&
255 (sapl2->SVE_tag != T_ATM_ANY))
258 sapl3 = &satm->satm_addr.t_atm_sap_layer3;
259 if (sapl3->SVE_tag == T_ATM_PRESENT) {
260 if ((sapl3->ID_type != T_ATM_SIMPLE_ID) &&
261 (sapl3->ID_type != T_ATM_IPI_ID) &&
262 (sapl3->ID_type != T_ATM_SNAP_ID) &&
263 (sapl3->ID_type != T_ATM_USER_ID))
265 } else if ((sapl3->SVE_tag != T_ATM_ABSENT) &&
266 (sapl3->SVE_tag != T_ATM_ANY))
269 sapapl = &satm->satm_addr.t_atm_sap_appl;
270 if (sapapl->SVE_tag == T_ATM_PRESENT) {
271 if ((sapapl->ID_type != T_ATM_ISO_APP_ID) &&
272 (sapapl->ID_type != T_ATM_USER_APP_ID) &&
273 (sapapl->ID_type != T_ATM_VENDOR_APP_ID))
275 } else if ((sapapl->SVE_tag != T_ATM_ABSENT) &&
276 (sapapl->SVE_tag != T_ATM_ANY))
280 * Create temporary attributes list so that we can check out the
281 * new bind parameters before we modify the socket's values;
283 attr = atp->atp_attr;
284 attr.called.tag = sapadr->SVE_tag_addr;
285 bcopy(&sapadr->address_format, &attr.called.addr, sizeof(Atm_addr));
287 attr.blli.tag_l2 = sapl2->SVE_tag;
288 if (sapl2->SVE_tag == T_ATM_PRESENT) {
289 attr.blli.v.layer_2_protocol.ID_type = sapl2->ID_type;
290 bcopy(&sapl2->ID, &attr.blli.v.layer_2_protocol.ID,
291 sizeof(attr.blli.v.layer_2_protocol.ID));
294 attr.blli.tag_l3 = sapl3->SVE_tag;
295 if (sapl3->SVE_tag == T_ATM_PRESENT) {
296 attr.blli.v.layer_3_protocol.ID_type = sapl3->ID_type;
297 bcopy(&sapl3->ID, &attr.blli.v.layer_3_protocol.ID,
298 sizeof(attr.blli.v.layer_3_protocol.ID));
301 attr.bhli.tag = sapapl->SVE_tag;
302 if (sapapl->SVE_tag == T_ATM_PRESENT) {
303 attr.bhli.v.ID_type = sapapl->ID_type;
304 bcopy(&sapapl->ID, &attr.bhli.v.ID,
305 sizeof(attr.bhli.v.ID));
309 * Make sure we have unique listening attributes
311 if (atm_cm_match(&attr, NULL) != NULL)
315 * Looks good, save new attributes
317 atp->atp_attr = attr;
324 * Listen for incoming connections
329 * so pointer to socket
330 * epp pointer to endpoint definition structure
333 * 0 request processed
334 * errno error processing request - reason indicated
338 atm_sock_listen(so, epp)
342 Atm_pcb *atp = sotoatmpcb(so);
345 * Make sure we're still attached
351 * Start listening for incoming calls
353 return (atm_cm_listen(so, epp, atp, &atp->atp_attr, &atp->atp_conn));
358 * Connect socket to peer
363 * so pointer to socket
364 * addr pointer to protocol address
365 * epp pointer to endpoint definition structure
368 * 0 request processed
369 * errno error processing request - reason indicated
373 atm_sock_connect(so, addr, epp)
375 struct sockaddr *addr;
378 Atm_pcb *atp = sotoatmpcb(so);
379 struct sockaddr_atm *satm;
380 struct t_atm_sap_addr *sapadr;
381 struct t_atm_sap_layer2 *sapl2;
382 struct t_atm_sap_layer3 *sapl3;
383 struct t_atm_sap_appl *sapapl;
387 * Make sure we're still attached
393 * Validate requested peer address
395 satm = (struct sockaddr_atm *)addr;
396 if (satm->satm_family != AF_ATM)
397 return (EAFNOSUPPORT);
399 sapadr = &satm->satm_addr.t_atm_sap_addr;
400 if (sapadr->SVE_tag_addr != T_ATM_PRESENT)
402 if (sapadr->address_format == T_ATM_ENDSYS_ADDR) {
403 if (sapadr->SVE_tag_selector != T_ATM_PRESENT)
405 } else if (sapadr->address_format == T_ATM_E164_ADDR) {
406 if (sapadr->SVE_tag_selector != T_ATM_ABSENT)
408 } else if (sapadr->address_format == T_ATM_PVC_ADDR) {
409 if (sapadr->SVE_tag_selector != T_ATM_ABSENT)
413 if (sapadr->address_length > ATM_ADDR_LEN)
416 sapl2 = &satm->satm_addr.t_atm_sap_layer2;
417 if (sapl2->SVE_tag == T_ATM_PRESENT) {
418 if ((sapl2->ID_type != T_ATM_SIMPLE_ID) &&
419 (sapl2->ID_type != T_ATM_USER_ID))
421 } else if (sapl2->SVE_tag != T_ATM_ABSENT)
424 sapl3 = &satm->satm_addr.t_atm_sap_layer3;
425 if (sapl3->SVE_tag == T_ATM_PRESENT) {
426 if ((sapl3->ID_type != T_ATM_SIMPLE_ID) &&
427 (sapl3->ID_type != T_ATM_IPI_ID) &&
428 (sapl3->ID_type != T_ATM_SNAP_ID) &&
429 (sapl3->ID_type != T_ATM_USER_ID))
431 } else if (sapl3->SVE_tag != T_ATM_ABSENT)
434 sapapl = &satm->satm_addr.t_atm_sap_appl;
435 if (sapapl->SVE_tag == T_ATM_PRESENT) {
436 if ((sapapl->ID_type != T_ATM_ISO_APP_ID) &&
437 (sapapl->ID_type != T_ATM_USER_APP_ID) &&
438 (sapapl->ID_type != T_ATM_VENDOR_APP_ID))
440 } else if (sapapl->SVE_tag != T_ATM_ABSENT)
444 * Select an outgoing network interface
446 if (atp->atp_attr.nif == NULL) {
449 for (pip = atm_interface_head; pip != NULL;
450 pip = pip->pif_next) {
451 if (pip->pif_nif != NULL) {
452 atp->atp_attr.nif = pip->pif_nif;
456 if (atp->atp_attr.nif == NULL)
461 * Set supplied connection attributes
463 atp->atp_attr.called.tag = T_ATM_PRESENT;
464 bcopy(&sapadr->address_format, &atp->atp_attr.called.addr,
467 atp->atp_attr.blli.tag_l2 = sapl2->SVE_tag;
468 if (sapl2->SVE_tag == T_ATM_PRESENT) {
469 atp->atp_attr.blli.v.layer_2_protocol.ID_type = sapl2->ID_type;
470 bcopy(&sapl2->ID, &atp->atp_attr.blli.v.layer_2_protocol.ID,
471 sizeof(atp->atp_attr.blli.v.layer_2_protocol.ID));
474 atp->atp_attr.blli.tag_l3 = sapl3->SVE_tag;
475 if (sapl3->SVE_tag == T_ATM_PRESENT) {
476 atp->atp_attr.blli.v.layer_3_protocol.ID_type = sapl3->ID_type;
477 bcopy(&sapl3->ID, &atp->atp_attr.blli.v.layer_3_protocol.ID,
478 sizeof(atp->atp_attr.blli.v.layer_3_protocol.ID));
481 atp->atp_attr.bhli.tag = sapapl->SVE_tag;
482 if (sapapl->SVE_tag == T_ATM_PRESENT) {
483 atp->atp_attr.bhli.v.ID_type = sapapl->ID_type;
484 bcopy(&sapapl->ID, &atp->atp_attr.bhli.v.ID,
485 sizeof(atp->atp_attr.bhli.v.ID));
489 * We're finally ready to initiate the ATM connection
492 atm_sock_stat.as_connreq[atp->atp_type]++;
493 err = atm_cm_connect(epp, atp, &atp->atp_attr, &atp->atp_conn);
496 * Connection is setup
498 atm_sock_stat.as_conncomp[atp->atp_type]++;
501 } else if (err == EINPROGRESS) {
503 * We've got to wait for a connected event
511 atm_sock_stat.as_connfail[atp->atp_type]++;
512 soisdisconnected(so);
520 * Disconnect connected socket
525 * so pointer to socket
528 * 0 request processed
529 * errno error processing request - reason indicated
533 atm_sock_disconnect(so)
536 Atm_pcb *atp = sotoatmpcb(so);
537 struct t_atm_cause *cause;
541 * Make sure we're still attached
547 * Release the ATM connection
550 if (atp->atp_attr.cause.tag == T_ATM_PRESENT)
551 cause = &atp->atp_attr.cause.v;
553 cause = &atm_sock_cause;
554 err = atm_cm_release(atp->atp_conn, cause);
556 log(LOG_ERR, "atm_sock_disconnect: release fail (%d)\n",
558 atm_sock_stat.as_connrel[atp->atp_type]++;
559 atp->atp_conn = NULL;
562 soisdisconnected(so);
569 * Retrieve local socket address
574 * so pointer to socket
575 * addr pointer to pointer to contain protocol address
578 * 0 request processed
579 * errno error processing request - reason indicated
583 atm_sock_sockaddr(so, addr)
585 struct sockaddr **addr;
587 struct sockaddr_atm *satm;
588 struct t_atm_sap_addr *saddr;
589 Atm_pcb *atp = sotoatmpcb(so);
592 * Return local interface address, if known
594 satm = malloc(sizeof(*satm), M_SONAME, M_WAITOK | M_ZERO);
598 satm->satm_family = AF_ATM;
599 satm->satm_len = sizeof(*satm);
601 saddr = &satm->satm_addr.t_atm_sap_addr;
602 if (atp->atp_attr.nif && atp->atp_attr.nif->nif_pif->pif_siginst) {
603 saddr->SVE_tag_addr = T_ATM_PRESENT;
605 &atp->atp_attr.nif->nif_pif->pif_siginst->si_addr,
606 atp->atp_attr.nif->nif_sel, saddr);
607 if (saddr->address_format == T_ATM_ENDSYS_ADDR)
608 saddr->SVE_tag_selector = T_ATM_PRESENT;
610 saddr->SVE_tag_selector = T_ATM_ABSENT;
612 saddr->SVE_tag_addr = T_ATM_ABSENT;
613 saddr->SVE_tag_selector = T_ATM_ABSENT;
614 saddr->address_format = T_ATM_ABSENT;
616 satm->satm_addr.t_atm_sap_layer2.SVE_tag = T_ATM_ABSENT;
617 satm->satm_addr.t_atm_sap_layer3.SVE_tag = T_ATM_ABSENT;
618 satm->satm_addr.t_atm_sap_appl.SVE_tag = T_ATM_ABSENT;
620 *addr = (struct sockaddr *)satm;
626 * Retrieve peer socket address
631 * so pointer to socket
632 * addr pointer to pointer to contain protocol address
635 * 0 request processed
636 * errno error processing request - reason indicated
640 atm_sock_peeraddr(so, addr)
642 struct sockaddr **addr;
644 struct sockaddr_atm *satm;
645 struct t_atm_sap_addr *saddr;
646 Atm_pcb *atp = sotoatmpcb(so);
650 * Return remote address, if known
652 satm = malloc(sizeof(*satm), M_SONAME, M_WAITOK | M_ZERO);
656 satm->satm_family = AF_ATM;
657 satm->satm_len = sizeof(*satm);
658 saddr = &satm->satm_addr.t_atm_sap_addr;
659 if (so->so_state & SS_ISCONNECTED) {
660 cvp = atp->atp_conn->co_connvc;
661 saddr->SVE_tag_addr = T_ATM_PRESENT;
662 if (cvp->cvc_flags & CVCF_CALLER) {
663 ATM_ADDR_COPY(&cvp->cvc_attr.called.addr, saddr);
665 if (cvp->cvc_attr.calling.tag == T_ATM_PRESENT) {
666 ATM_ADDR_COPY(&cvp->cvc_attr.calling.addr,
669 saddr->SVE_tag_addr = T_ATM_ABSENT;
670 saddr->address_format = T_ATM_ABSENT;
673 if (saddr->address_format == T_ATM_ENDSYS_ADDR)
674 saddr->SVE_tag_selector = T_ATM_PRESENT;
676 saddr->SVE_tag_selector = T_ATM_ABSENT;
678 saddr->SVE_tag_addr = T_ATM_ABSENT;
679 saddr->SVE_tag_selector = T_ATM_ABSENT;
680 saddr->address_format = T_ATM_ABSENT;
682 satm->satm_addr.t_atm_sap_layer2.SVE_tag = T_ATM_ABSENT;
683 satm->satm_addr.t_atm_sap_layer3.SVE_tag = T_ATM_ABSENT;
684 satm->satm_addr.t_atm_sap_appl.SVE_tag = T_ATM_ABSENT;
686 *addr = (struct sockaddr *)satm;
692 * Common setsockopt processing
697 * so pointer to socket
698 * sopt pointer to socket option info
699 * atp pointer to ATM PCB
702 * 0 request processed
703 * errno error processing request - reason indicated
707 atm_sock_setopt(so, sopt, atp)
709 struct sockopt *sopt;
714 struct t_atm_aal5 aal5;
715 struct t_atm_traffic trf;
716 struct t_atm_bearer brr;
717 struct t_atm_bhli bhl;
718 struct t_atm_blli bll;
720 struct t_atm_cause cau;
721 struct t_atm_qos qos;
722 struct t_atm_transit trn;
723 struct t_atm_net_intf nif;
724 struct t_atm_llc llc;
725 struct t_atm_app_name appn;
728 #define MAXVAL(bits) ((1 << bits) - 1)
729 #define MAXMASK(bits) (~MAXVAL(bits))
731 switch (sopt->sopt_name) {
734 err = sooptcopyin(sopt, &p.aal5, sizeof p.aal5, sizeof p.aal5);
737 if ((p.aal5.forward_max_SDU_size != T_ATM_ABSENT) &&
738 (p.aal5.forward_max_SDU_size & MAXMASK(16)))
740 if ((p.aal5.backward_max_SDU_size != T_ATM_ABSENT) &&
741 (p.aal5.backward_max_SDU_size & MAXMASK(16)))
743 if ((p.aal5.SSCS_type != T_ATM_ABSENT) &&
744 (p.aal5.SSCS_type != T_ATM_NULL) &&
745 (p.aal5.SSCS_type != T_ATM_SSCS_SSCOP_REL) &&
746 (p.aal5.SSCS_type != T_ATM_SSCS_SSCOP_UNREL) &&
747 (p.aal5.SSCS_type != T_ATM_SSCS_FR))
750 if ((p.aal5.forward_max_SDU_size == T_ATM_ABSENT) &&
751 (p.aal5.backward_max_SDU_size == T_ATM_ABSENT) &&
752 (p.aal5.SSCS_type == T_ATM_ABSENT))
753 atp->atp_attr.aal.tag = T_ATM_ABSENT;
755 atp->atp_attr.aal.tag = T_ATM_PRESENT;
756 atp->atp_attr.aal.type = ATM_AAL5;
757 atp->atp_attr.aal.v.aal5 = p.aal5;
762 err = sooptcopyin(sopt, &p.trf, sizeof p.trf, sizeof p.trf);
765 if ((p.trf.forward.PCR_high_priority != T_ATM_ABSENT) &&
766 (p.trf.forward.PCR_high_priority & MAXMASK(24)))
768 if (p.trf.forward.PCR_all_traffic & MAXMASK(24))
770 if ((p.trf.forward.SCR_high_priority != T_ATM_ABSENT) &&
771 (p.trf.forward.SCR_high_priority & MAXMASK(24)))
773 if ((p.trf.forward.SCR_all_traffic != T_ATM_ABSENT) &&
774 (p.trf.forward.SCR_all_traffic & MAXMASK(24)))
776 if ((p.trf.forward.MBS_high_priority != T_ATM_ABSENT) &&
777 (p.trf.forward.MBS_high_priority & MAXMASK(24)))
779 if ((p.trf.forward.MBS_all_traffic != T_ATM_ABSENT) &&
780 (p.trf.forward.MBS_all_traffic & MAXMASK(24)))
782 if ((p.trf.forward.tagging != T_YES) &&
783 (p.trf.forward.tagging != T_NO))
786 if ((p.trf.backward.PCR_high_priority != T_ATM_ABSENT) &&
787 (p.trf.backward.PCR_high_priority & MAXMASK(24)))
789 if (p.trf.backward.PCR_all_traffic & MAXMASK(24))
791 if ((p.trf.backward.SCR_high_priority != T_ATM_ABSENT) &&
792 (p.trf.backward.SCR_high_priority & MAXMASK(24)))
794 if ((p.trf.backward.SCR_all_traffic != T_ATM_ABSENT) &&
795 (p.trf.backward.SCR_all_traffic & MAXMASK(24)))
797 if ((p.trf.backward.MBS_high_priority != T_ATM_ABSENT) &&
798 (p.trf.backward.MBS_high_priority & MAXMASK(24)))
800 if ((p.trf.backward.MBS_all_traffic != T_ATM_ABSENT) &&
801 (p.trf.backward.MBS_all_traffic & MAXMASK(24)))
803 if ((p.trf.backward.tagging != T_YES) &&
804 (p.trf.backward.tagging != T_NO))
806 if ((p.trf.best_effort != T_YES) &&
807 (p.trf.best_effort != T_NO))
810 atp->atp_attr.traffic.tag = T_ATM_PRESENT;
811 atp->atp_attr.traffic.v = p.trf;
814 case T_ATM_BEARER_CAP:
815 err = sooptcopyin(sopt, &p.brr, sizeof p.brr, sizeof p.brr);
818 if ((p.brr.bearer_class != T_ATM_CLASS_A) &&
819 (p.brr.bearer_class != T_ATM_CLASS_C) &&
820 (p.brr.bearer_class != T_ATM_CLASS_X))
822 if ((p.brr.traffic_type != T_ATM_NULL) &&
823 (p.brr.traffic_type != T_ATM_CBR) &&
824 (p.brr.traffic_type != T_ATM_VBR) &&
825 (p.brr.traffic_type != T_ATM_ABR) &&
826 (p.brr.traffic_type != T_ATM_UBR))
828 if ((p.brr.timing_requirements != T_ATM_NULL) &&
829 (p.brr.timing_requirements != T_ATM_END_TO_END) &&
830 (p.brr.timing_requirements != T_ATM_NO_END_TO_END))
832 if ((p.brr.clipping_susceptibility != T_NO) &&
833 (p.brr.clipping_susceptibility != T_YES))
835 if ((p.brr.connection_configuration != T_ATM_1_TO_1) &&
836 (p.brr.connection_configuration != T_ATM_1_TO_MANY))
839 atp->atp_attr.bearer.tag = T_ATM_PRESENT;
840 atp->atp_attr.bearer.v = p.brr;
844 err = sooptcopyin(sopt, &p.bhl, sizeof p.bhl, sizeof p.bhl);
847 if ((p.bhl.ID_type != T_ATM_ABSENT) &&
848 (p.bhl.ID_type != T_ATM_ISO_APP_ID) &&
849 (p.bhl.ID_type != T_ATM_USER_APP_ID) &&
850 (p.bhl.ID_type != T_ATM_VENDOR_APP_ID))
853 if (p.bhl.ID_type == T_ATM_ABSENT)
854 atp->atp_attr.bhli.tag = T_ATM_ABSENT;
856 atp->atp_attr.bhli.tag = T_ATM_PRESENT;
857 atp->atp_attr.bhli.v = p.bhl;
862 err = sooptcopyin(sopt, &p.bll, sizeof p.bll, sizeof p.bll);
865 if ((p.bll.layer_2_protocol.ID_type != T_ATM_ABSENT) &&
866 (p.bll.layer_2_protocol.ID_type != T_ATM_SIMPLE_ID) &&
867 (p.bll.layer_2_protocol.ID_type != T_ATM_USER_ID))
869 if ((p.bll.layer_2_protocol.mode != T_ATM_ABSENT) &&
870 (p.bll.layer_2_protocol.mode != T_ATM_BLLI_NORMAL_MODE) &&
871 (p.bll.layer_2_protocol.mode != T_ATM_BLLI_EXTENDED_MODE))
873 if ((p.bll.layer_2_protocol.window_size != T_ATM_ABSENT) &&
874 (p.bll.layer_2_protocol.window_size < 1))
877 if ((p.bll.layer_3_protocol.ID_type != T_ATM_ABSENT) &&
878 (p.bll.layer_3_protocol.ID_type != T_ATM_SIMPLE_ID) &&
879 (p.bll.layer_3_protocol.ID_type != T_ATM_IPI_ID) &&
880 (p.bll.layer_3_protocol.ID_type != T_ATM_SNAP_ID) &&
881 (p.bll.layer_3_protocol.ID_type != T_ATM_USER_ID))
883 if ((p.bll.layer_3_protocol.mode != T_ATM_ABSENT) &&
884 (p.bll.layer_3_protocol.mode != T_ATM_BLLI_NORMAL_MODE) &&
885 (p.bll.layer_3_protocol.mode != T_ATM_BLLI_EXTENDED_MODE))
887 if ((p.bll.layer_3_protocol.packet_size != T_ATM_ABSENT) &&
888 (p.bll.layer_3_protocol.packet_size & MAXMASK(4)))
890 if ((p.bll.layer_3_protocol.window_size != T_ATM_ABSENT) &&
891 (p.bll.layer_3_protocol.window_size < 1))
894 if (p.bll.layer_2_protocol.ID_type == T_ATM_ABSENT)
895 atp->atp_attr.blli.tag_l2 = T_ATM_ABSENT;
897 atp->atp_attr.blli.tag_l2 = T_ATM_PRESENT;
899 if (p.bll.layer_3_protocol.ID_type == T_ATM_ABSENT)
900 atp->atp_attr.blli.tag_l3 = T_ATM_ABSENT;
902 atp->atp_attr.blli.tag_l3 = T_ATM_PRESENT;
904 if ((atp->atp_attr.blli.tag_l2 == T_ATM_PRESENT) ||
905 (atp->atp_attr.blli.tag_l3 == T_ATM_PRESENT))
906 atp->atp_attr.blli.v = p.bll;
909 case T_ATM_DEST_ADDR:
910 err = sooptcopyin(sopt, &p.addr, sizeof p.addr, sizeof p.addr);
913 if ((p.addr.address_format != T_ATM_ENDSYS_ADDR) &&
914 (p.addr.address_format != T_ATM_E164_ADDR))
916 if (p.addr.address_length > ATM_ADDR_LEN)
919 atp->atp_attr.called.tag = T_ATM_PRESENT;
920 atp->atp_attr.called.addr = p.addr;
924 err = sooptcopyin(sopt, &p.addr, sizeof p.addr, sizeof p.addr);
927 if ((p.addr.address_format != T_ATM_ABSENT) &&
928 (p.addr.address_format != T_ATM_NSAP_ADDR))
930 if (p.addr.address_length > ATM_ADDR_LEN)
933 /* T_ATM_DEST_ADDR controls tag */
934 atp->atp_attr.called.subaddr = p.addr;
937 case T_ATM_ORIG_ADDR:
943 case T_ATM_CALLER_ID:
947 err = sooptcopyin(sopt, &p.cau, sizeof p.cau, sizeof p.cau);
950 if ((p.cau.coding_standard != T_ATM_ABSENT) &&
951 (p.cau.coding_standard != T_ATM_ITU_CODING) &&
952 (p.cau.coding_standard != T_ATM_NETWORK_CODING))
954 if ((p.cau.location != T_ATM_LOC_USER) &&
955 (p.cau.location != T_ATM_LOC_LOCAL_PRIVATE_NET) &&
956 (p.cau.location != T_ATM_LOC_LOCAL_PUBLIC_NET) &&
957 (p.cau.location != T_ATM_LOC_TRANSIT_NET) &&
958 (p.cau.location != T_ATM_LOC_REMOTE_PUBLIC_NET) &&
959 (p.cau.location != T_ATM_LOC_REMOTE_PRIVATE_NET) &&
960 (p.cau.location != T_ATM_LOC_INTERNATIONAL_NET) &&
961 (p.cau.location != T_ATM_LOC_BEYOND_INTERWORKING))
964 if (p.cau.coding_standard == T_ATM_ABSENT)
965 atp->atp_attr.cause.tag = T_ATM_ABSENT;
967 atp->atp_attr.cause.tag = T_ATM_PRESENT;
968 atp->atp_attr.cause.v = p.cau;
973 err = sooptcopyin(sopt, &p.qos, sizeof p.qos, sizeof p.qos);
976 if ((p.qos.coding_standard != T_ATM_ABSENT) &&
977 (p.qos.coding_standard != T_ATM_ITU_CODING) &&
978 (p.qos.coding_standard != T_ATM_NETWORK_CODING))
980 if ((p.qos.forward.qos_class != T_ATM_QOS_CLASS_0) &&
981 (p.qos.forward.qos_class != T_ATM_QOS_CLASS_1) &&
982 (p.qos.forward.qos_class != T_ATM_QOS_CLASS_2) &&
983 (p.qos.forward.qos_class != T_ATM_QOS_CLASS_3) &&
984 (p.qos.forward.qos_class != T_ATM_QOS_CLASS_4))
986 if ((p.qos.backward.qos_class != T_ATM_QOS_CLASS_0) &&
987 (p.qos.backward.qos_class != T_ATM_QOS_CLASS_1) &&
988 (p.qos.backward.qos_class != T_ATM_QOS_CLASS_2) &&
989 (p.qos.backward.qos_class != T_ATM_QOS_CLASS_3) &&
990 (p.qos.backward.qos_class != T_ATM_QOS_CLASS_4))
993 if (p.qos.coding_standard == T_ATM_ABSENT)
994 atp->atp_attr.qos.tag = T_ATM_ABSENT;
996 atp->atp_attr.qos.tag = T_ATM_PRESENT;
997 atp->atp_attr.qos.v = p.qos;
1002 err = sooptcopyin(sopt, &p.trn, sizeof p.trn, sizeof p.trn);
1005 if (p.trn.length > T_ATM_MAX_NET_ID)
1008 if (p.trn.length == 0)
1009 atp->atp_attr.transit.tag = T_ATM_ABSENT;
1011 atp->atp_attr.transit.tag = T_ATM_PRESENT;
1012 atp->atp_attr.transit.v = p.trn;
1016 case T_ATM_ADD_LEAF:
1017 return (EPROTONOSUPPORT); /* XXX */
1019 case T_ATM_DROP_LEAF:
1020 return (EPROTONOSUPPORT); /* XXX */
1022 case T_ATM_NET_INTF:
1023 err = sooptcopyin(sopt, &p.nif, sizeof p.nif, sizeof p.nif);
1027 atp->atp_attr.nif = atm_nifname(p.nif.net_intf);
1028 if (atp->atp_attr.nif == NULL)
1033 err = sooptcopyin(sopt, &p.llc, sizeof p.llc, sizeof p.llc);
1036 if ((p.llc.llc_len < T_ATM_LLC_MIN_LEN) ||
1037 (p.llc.llc_len > T_ATM_LLC_MAX_LEN))
1040 atp->atp_attr.llc.tag = T_ATM_PRESENT;
1041 atp->atp_attr.llc.v = p.llc;
1044 case T_ATM_APP_NAME:
1045 err = sooptcopyin(sopt, &p.appn, sizeof p.appn, sizeof p.appn);
1049 strncpy(atp->atp_name, p.appn.app_name, T_ATM_APP_NAME_LEN);
1053 return (ENOPROTOOPT);
1061 * Common getsockopt processing
1066 * so pointer to socket
1067 * sopt pointer to socket option info
1068 * atp pointer to ATM PCB
1071 * 0 request processed
1072 * errno error processing request - reason indicated
1076 atm_sock_getopt(so, sopt, atp)
1078 struct sockopt *sopt;
1084 * If socket is connected, return attributes for the VCC in use,
1085 * otherwise just return what the user has setup so far.
1087 if (so->so_state & SS_ISCONNECTED)
1088 ap = &atp->atp_conn->co_connvc->cvc_attr;
1090 ap = &atp->atp_attr;
1092 switch (sopt->sopt_name) {
1095 if ((ap->aal.tag == T_ATM_PRESENT) &&
1096 (ap->aal.type == ATM_AAL5)) {
1097 return (sooptcopyout(sopt, &ap->aal.v.aal5,
1098 sizeof ap->aal.v.aal5));
1105 if (ap->traffic.tag == T_ATM_PRESENT) {
1106 return (sooptcopyout(sopt, &ap->traffic.v,
1107 sizeof ap->traffic.v));
1113 case T_ATM_BEARER_CAP:
1114 if (ap->bearer.tag == T_ATM_PRESENT) {
1115 return (sooptcopyout(sopt, &ap->bearer.v,
1116 sizeof ap->bearer.v));
1123 if (ap->bhli.tag == T_ATM_PRESENT) {
1124 return (sooptcopyout(sopt, &ap->bhli.v,
1125 sizeof ap->bhli.v));
1132 if ((ap->blli.tag_l2 == T_ATM_PRESENT) ||
1133 (ap->blli.tag_l3 == T_ATM_PRESENT)) {
1134 return (sooptcopyout(sopt, &ap->blli.v,
1135 sizeof ap->blli.v));
1141 case T_ATM_DEST_ADDR:
1142 if (ap->called.tag == T_ATM_PRESENT) {
1143 return (sooptcopyout(sopt, &ap->called.addr,
1144 sizeof ap->called.addr));
1150 case T_ATM_DEST_SUB:
1151 if (ap->called.tag == T_ATM_PRESENT) {
1152 return (sooptcopyout(sopt, &ap->called.subaddr,
1153 sizeof ap->called.subaddr));
1159 case T_ATM_ORIG_ADDR:
1160 if (ap->calling.tag == T_ATM_PRESENT) {
1161 return (sooptcopyout(sopt, &ap->calling.addr,
1162 sizeof ap->calling.addr));
1168 case T_ATM_ORIG_SUB:
1169 if (ap->calling.tag == T_ATM_PRESENT) {
1170 return (sooptcopyout(sopt, &ap->calling.subaddr,
1171 sizeof ap->calling.subaddr));
1177 case T_ATM_CALLER_ID:
1178 if (ap->calling.tag == T_ATM_PRESENT) {
1179 return (sooptcopyout(sopt, &ap->calling.cid,
1180 sizeof ap->calling.cid));
1187 if (ap->cause.tag == T_ATM_PRESENT) {
1188 return (sooptcopyout(sopt, &ap->cause.v,
1189 sizeof ap->cause.v));
1196 if (ap->qos.tag == T_ATM_PRESENT) {
1197 return (sooptcopyout(sopt, &ap->qos.v,
1205 if (ap->transit.tag == T_ATM_PRESENT) {
1206 return (sooptcopyout(sopt, &ap->transit.v,
1207 sizeof ap->transit.v));
1213 case T_ATM_LEAF_IND:
1214 return (EPROTONOSUPPORT); /* XXX */
1216 case T_ATM_NET_INTF:
1218 struct t_atm_net_intf netif;
1221 ifp = &ap->nif->nif_if;
1222 (void) snprintf(netif.net_intf, sizeof(netif.net_intf),
1223 "%s", ifp->if_xname);
1224 return (sooptcopyout(sopt, &netif,
1232 if (ap->llc.tag == T_ATM_PRESENT) {
1233 return (sooptcopyout(sopt, &ap->llc.v,
1241 return (ENOPROTOOPT);
1249 * Process Socket VCC Connected Notification
1252 * toku owner's connection token (atm_pcb protocol block)
1259 atm_sock_connected(toku)
1262 Atm_pcb *atp = (Atm_pcb *)toku;
1265 * Connection is setup
1267 atm_sock_stat.as_conncomp[atp->atp_type]++;
1268 soisconnected(atp->atp_socket);
1273 * Process Socket VCC Cleared Notification
1276 * toku owner's connection token (atm_pcb protocol block)
1277 * cause pointer to cause code
1284 atm_sock_cleared(toku, cause)
1286 struct t_atm_cause *cause;
1288 Atm_pcb *atp = (Atm_pcb *)toku;
1291 so = atp->atp_socket;
1294 * Save call clearing cause
1296 atp->atp_attr.cause.tag = T_ATM_PRESENT;
1297 atp->atp_attr.cause.v = *cause;
1300 * Set user error code
1302 if (so->so_state & SS_ISCONNECTED) {
1303 so->so_error = ECONNRESET;
1304 atm_sock_stat.as_connclr[atp->atp_type]++;
1306 so->so_error = ECONNREFUSED;
1307 atm_sock_stat.as_connfail[atp->atp_type]++;
1311 * Connection is gone
1313 atp->atp_conn = NULL;
1314 soisdisconnected(so);
1317 * Cleanup failed incoming connection setup
1319 if (so->so_state & SS_NOFDREF) {
1320 (void) atm_sock_detach(so);