3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/atm_socket.c,v 1.4 1999/08/28 00:48:37 peter Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/atm_socket.c,v 1.8 2006/01/14 13:36:39 swildner Exp $
34 * ATM common socket protocol processing
38 #include "kern_include.h"
48 static struct sp_info atm_pcb_pool
= {
49 "atm pcb pool", /* si_name */
50 sizeof(Atm_pcb
), /* si_blksiz */
55 static struct t_atm_cause atm_sock_cause
= {
58 T_ATM_CAUSE_UNSPECIFIED_NORMAL
,
64 * Allocate resources for a new ATM socket
69 * so pointer to socket
70 * send socket send buffer maximum
71 * recv socket receive buffer maximum
75 * errno attach failed - reason indicated
79 atm_sock_attach(struct socket
*so
, u_long send
, u_long recv
, struct rlimit
*rl
)
81 Atm_pcb
*atp
= sotoatmpcb(so
);
85 * Make sure initialization has happened
91 * Make sure we're not already attached
97 * Reserve socket buffer space, if not already done
99 if ((so
->so_snd
.sb_hiwat
== 0) || (so
->so_rcv
.sb_hiwat
== 0)) {
100 err
= soreserve(so
, send
, recv
, rl
);
106 * Allocate and initialize our control block
108 atp
= (Atm_pcb
*)atm_allocate(&atm_pcb_pool
);
112 atp
->atp_socket
= so
;
113 so
->so_pcb
= (caddr_t
)atp
;
119 * Detach from socket and free resources
124 * so pointer to socket
127 * 0 detach successful
128 * errno detach failed - reason indicated
132 atm_sock_detach(struct socket
*so
)
134 Atm_pcb
*atp
= sotoatmpcb(so
);
137 * Make sure we're still attached
143 * Terminate any (possibly pending) connection
146 atm_sock_disconnect(so
);
150 * Break links and free control blocks
155 atm_free((caddr_t
)atp
);
162 * Bind local address to socket
167 * so pointer to socket
168 * addr pointer to protocol address
171 * 0 request processed
172 * errno error processing request - reason indicated
176 atm_sock_bind(struct socket
*so
, struct sockaddr
*addr
)
178 Atm_pcb
*atp
= sotoatmpcb(so
);
180 struct sockaddr_atm
*satm
;
181 struct t_atm_sap_addr
*sapadr
;
182 struct t_atm_sap_layer2
*sapl2
;
183 struct t_atm_sap_layer3
*sapl3
;
184 struct t_atm_sap_appl
*sapapl
;
187 * Make sure we're still attached
193 * Can't change local address once we've started connection process
195 if (atp
->atp_conn
!= NULL
)
196 return (EADDRNOTAVAIL
);
199 * Validate requested local address
201 satm
= (struct sockaddr_atm
*)addr
;
202 if (satm
->satm_family
!= AF_ATM
)
203 return (EAFNOSUPPORT
);
205 sapadr
= &satm
->satm_addr
.t_atm_sap_addr
;
206 if (sapadr
->SVE_tag_addr
== T_ATM_PRESENT
) {
207 if (sapadr
->address_format
== T_ATM_ENDSYS_ADDR
) {
208 if (sapadr
->SVE_tag_selector
!= T_ATM_PRESENT
)
210 } else if (sapadr
->address_format
== T_ATM_E164_ADDR
) {
211 if (sapadr
->SVE_tag_selector
!= T_ATM_ABSENT
)
215 } else if ((sapadr
->SVE_tag_addr
!= T_ATM_ABSENT
) &&
216 (sapadr
->SVE_tag_addr
!= T_ATM_ANY
))
218 if (sapadr
->address_length
> ATM_ADDR_LEN
)
221 sapl2
= &satm
->satm_addr
.t_atm_sap_layer2
;
222 if (sapl2
->SVE_tag
== T_ATM_PRESENT
) {
223 if ((sapl2
->ID_type
!= T_ATM_SIMPLE_ID
) &&
224 (sapl2
->ID_type
!= T_ATM_USER_ID
))
226 } else if ((sapl2
->SVE_tag
!= T_ATM_ABSENT
) &&
227 (sapl2
->SVE_tag
!= T_ATM_ANY
))
230 sapl3
= &satm
->satm_addr
.t_atm_sap_layer3
;
231 if (sapl3
->SVE_tag
== T_ATM_PRESENT
) {
232 if ((sapl3
->ID_type
!= T_ATM_SIMPLE_ID
) &&
233 (sapl3
->ID_type
!= T_ATM_IPI_ID
) &&
234 (sapl3
->ID_type
!= T_ATM_SNAP_ID
) &&
235 (sapl3
->ID_type
!= T_ATM_USER_ID
))
237 } else if ((sapl3
->SVE_tag
!= T_ATM_ABSENT
) &&
238 (sapl3
->SVE_tag
!= T_ATM_ANY
))
241 sapapl
= &satm
->satm_addr
.t_atm_sap_appl
;
242 if (sapapl
->SVE_tag
== T_ATM_PRESENT
) {
243 if ((sapapl
->ID_type
!= T_ATM_ISO_APP_ID
) &&
244 (sapapl
->ID_type
!= T_ATM_USER_APP_ID
) &&
245 (sapapl
->ID_type
!= T_ATM_VENDOR_APP_ID
))
247 } else if ((sapapl
->SVE_tag
!= T_ATM_ABSENT
) &&
248 (sapapl
->SVE_tag
!= T_ATM_ANY
))
252 * Create temporary attributes list so that we can check out the
253 * new bind parameters before we modify the socket's values;
255 attr
= atp
->atp_attr
;
256 attr
.called
.tag
= sapadr
->SVE_tag_addr
;
257 KM_COPY(&sapadr
->address_format
, &attr
.called
.addr
, sizeof(Atm_addr
));
259 attr
.blli
.tag_l2
= sapl2
->SVE_tag
;
260 if (sapl2
->SVE_tag
== T_ATM_PRESENT
) {
261 attr
.blli
.v
.layer_2_protocol
.ID_type
= sapl2
->ID_type
;
262 KM_COPY(&sapl2
->ID
, &attr
.blli
.v
.layer_2_protocol
.ID
,
263 sizeof(attr
.blli
.v
.layer_2_protocol
.ID
));
266 attr
.blli
.tag_l3
= sapl3
->SVE_tag
;
267 if (sapl3
->SVE_tag
== T_ATM_PRESENT
) {
268 attr
.blli
.v
.layer_3_protocol
.ID_type
= sapl3
->ID_type
;
269 KM_COPY(&sapl3
->ID
, &attr
.blli
.v
.layer_3_protocol
.ID
,
270 sizeof(attr
.blli
.v
.layer_3_protocol
.ID
));
273 attr
.bhli
.tag
= sapapl
->SVE_tag
;
274 if (sapapl
->SVE_tag
== T_ATM_PRESENT
) {
275 attr
.bhli
.v
.ID_type
= sapapl
->ID_type
;
276 KM_COPY(&sapapl
->ID
, &attr
.bhli
.v
.ID
,
277 sizeof(attr
.bhli
.v
.ID
));
281 * Make sure we have unique listening attributes
283 if (atm_cm_match(&attr
, NULL
) != NULL
)
287 * Looks good, save new attributes
289 atp
->atp_attr
= attr
;
296 * Listen for incoming connections
301 * so pointer to socket
302 * epp pointer to endpoint definition structure
305 * 0 request processed
306 * errno error processing request - reason indicated
310 atm_sock_listen(struct socket
*so
, Atm_endpoint
*epp
)
312 Atm_pcb
*atp
= sotoatmpcb(so
);
315 * Make sure we're still attached
321 * Start listening for incoming calls
323 return (atm_cm_listen(epp
, atp
, &atp
->atp_attr
, &atp
->atp_conn
));
328 * Connect socket to peer
333 * so pointer to socket
334 * addr pointer to protocol address
335 * epp pointer to endpoint definition structure
338 * 0 request processed
339 * errno error processing request - reason indicated
343 atm_sock_connect(struct socket
*so
, struct sockaddr
*addr
, Atm_endpoint
*epp
)
345 Atm_pcb
*atp
= sotoatmpcb(so
);
346 struct sockaddr_atm
*satm
;
347 struct t_atm_sap_addr
*sapadr
;
348 struct t_atm_sap_layer2
*sapl2
;
349 struct t_atm_sap_layer3
*sapl3
;
350 struct t_atm_sap_appl
*sapapl
;
354 * Make sure we're still attached
360 * Validate requested peer address
362 satm
= (struct sockaddr_atm
*)addr
;
363 if (satm
->satm_family
!= AF_ATM
)
364 return (EAFNOSUPPORT
);
366 sapadr
= &satm
->satm_addr
.t_atm_sap_addr
;
367 if (sapadr
->SVE_tag_addr
!= T_ATM_PRESENT
)
369 if (sapadr
->address_format
== T_ATM_ENDSYS_ADDR
) {
370 if (sapadr
->SVE_tag_selector
!= T_ATM_PRESENT
)
372 } else if (sapadr
->address_format
== T_ATM_E164_ADDR
) {
373 if (sapadr
->SVE_tag_selector
!= T_ATM_ABSENT
)
375 } else if (sapadr
->address_format
== T_ATM_PVC_ADDR
) {
376 if (sapadr
->SVE_tag_selector
!= T_ATM_ABSENT
)
380 if (sapadr
->address_length
> ATM_ADDR_LEN
)
383 sapl2
= &satm
->satm_addr
.t_atm_sap_layer2
;
384 if (sapl2
->SVE_tag
== T_ATM_PRESENT
) {
385 if ((sapl2
->ID_type
!= T_ATM_SIMPLE_ID
) &&
386 (sapl2
->ID_type
!= T_ATM_USER_ID
))
388 } else if (sapl2
->SVE_tag
!= T_ATM_ABSENT
)
391 sapl3
= &satm
->satm_addr
.t_atm_sap_layer3
;
392 if (sapl3
->SVE_tag
== T_ATM_PRESENT
) {
393 if ((sapl3
->ID_type
!= T_ATM_SIMPLE_ID
) &&
394 (sapl3
->ID_type
!= T_ATM_IPI_ID
) &&
395 (sapl3
->ID_type
!= T_ATM_SNAP_ID
) &&
396 (sapl3
->ID_type
!= T_ATM_USER_ID
))
398 } else if (sapl3
->SVE_tag
!= T_ATM_ABSENT
)
401 sapapl
= &satm
->satm_addr
.t_atm_sap_appl
;
402 if (sapapl
->SVE_tag
== T_ATM_PRESENT
) {
403 if ((sapapl
->ID_type
!= T_ATM_ISO_APP_ID
) &&
404 (sapapl
->ID_type
!= T_ATM_USER_APP_ID
) &&
405 (sapapl
->ID_type
!= T_ATM_VENDOR_APP_ID
))
407 } else if (sapapl
->SVE_tag
!= T_ATM_ABSENT
)
411 * Select an outgoing network interface
413 if (atp
->atp_attr
.nif
== NULL
) {
416 for (pip
= atm_interface_head
; pip
!= NULL
;
417 pip
= pip
->pif_next
) {
418 if (pip
->pif_nif
!= NULL
) {
419 atp
->atp_attr
.nif
= pip
->pif_nif
;
423 if (atp
->atp_attr
.nif
== NULL
)
428 * Set supplied connection attributes
430 atp
->atp_attr
.called
.tag
= T_ATM_PRESENT
;
431 KM_COPY(&sapadr
->address_format
, &atp
->atp_attr
.called
.addr
,
434 atp
->atp_attr
.blli
.tag_l2
= sapl2
->SVE_tag
;
435 if (sapl2
->SVE_tag
== T_ATM_PRESENT
) {
436 atp
->atp_attr
.blli
.v
.layer_2_protocol
.ID_type
= sapl2
->ID_type
;
437 KM_COPY(&sapl2
->ID
, &atp
->atp_attr
.blli
.v
.layer_2_protocol
.ID
,
438 sizeof(atp
->atp_attr
.blli
.v
.layer_2_protocol
.ID
));
441 atp
->atp_attr
.blli
.tag_l3
= sapl3
->SVE_tag
;
442 if (sapl3
->SVE_tag
== T_ATM_PRESENT
) {
443 atp
->atp_attr
.blli
.v
.layer_3_protocol
.ID_type
= sapl3
->ID_type
;
444 KM_COPY(&sapl3
->ID
, &atp
->atp_attr
.blli
.v
.layer_3_protocol
.ID
,
445 sizeof(atp
->atp_attr
.blli
.v
.layer_3_protocol
.ID
));
448 atp
->atp_attr
.bhli
.tag
= sapapl
->SVE_tag
;
449 if (sapapl
->SVE_tag
== T_ATM_PRESENT
) {
450 atp
->atp_attr
.bhli
.v
.ID_type
= sapapl
->ID_type
;
451 KM_COPY(&sapapl
->ID
, &atp
->atp_attr
.bhli
.v
.ID
,
452 sizeof(atp
->atp_attr
.bhli
.v
.ID
));
456 * We're finally ready to initiate the ATM connection
459 atm_sock_stat
.as_connreq
[atp
->atp_type
]++;
460 err
= atm_cm_connect(epp
, atp
, &atp
->atp_attr
, &atp
->atp_conn
);
463 * Connection is setup
465 atm_sock_stat
.as_conncomp
[atp
->atp_type
]++;
468 } else if (err
== EINPROGRESS
) {
470 * We've got to wait for a connected event
478 atm_sock_stat
.as_connfail
[atp
->atp_type
]++;
479 soisdisconnected(so
);
487 * Disconnect connected socket
492 * so pointer to socket
495 * 0 request processed
496 * errno error processing request - reason indicated
500 atm_sock_disconnect(struct socket
*so
)
502 Atm_pcb
*atp
= sotoatmpcb(so
);
503 struct t_atm_cause
*cause
;
507 * Make sure we're still attached
513 * Release the ATM connection
516 if (atp
->atp_attr
.cause
.tag
== T_ATM_PRESENT
)
517 cause
= &atp
->atp_attr
.cause
.v
;
519 cause
= &atm_sock_cause
;
520 err
= atm_cm_release(atp
->atp_conn
, cause
);
522 log(LOG_ERR
, "atm_sock_disconnect: release fail (%d)\n",
524 atm_sock_stat
.as_connrel
[atp
->atp_type
]++;
525 atp
->atp_conn
= NULL
;
528 soisdisconnected(so
);
535 * Retrieve local socket address
540 * so pointer to socket
541 * addr pointer to pointer to contain protocol address
544 * 0 request processed
545 * errno error processing request - reason indicated
549 atm_sock_sockaddr(struct socket
*so
, struct sockaddr
**addr
)
551 struct sockaddr_atm
*satm
;
552 struct t_atm_sap_addr
*saddr
;
553 Atm_pcb
*atp
= sotoatmpcb(so
);
556 * Return local interface address, if known
558 satm
= KM_ALLOC(sizeof *satm
, M_SONAME
, M_WAITOK
);
562 KM_ZERO(satm
, sizeof(*satm
));
563 satm
->satm_family
= AF_ATM
;
564 satm
->satm_len
= sizeof(*satm
);
566 saddr
= &satm
->satm_addr
.t_atm_sap_addr
;
567 if (atp
->atp_attr
.nif
&& atp
->atp_attr
.nif
->nif_pif
->pif_siginst
) {
568 saddr
->SVE_tag_addr
= T_ATM_PRESENT
;
570 &atp
->atp_attr
.nif
->nif_pif
->pif_siginst
->si_addr
,
571 atp
->atp_attr
.nif
->nif_sel
, saddr
);
572 if (saddr
->address_format
== T_ATM_ENDSYS_ADDR
)
573 saddr
->SVE_tag_selector
= T_ATM_PRESENT
;
575 saddr
->SVE_tag_selector
= T_ATM_ABSENT
;
577 saddr
->SVE_tag_addr
= T_ATM_ABSENT
;
578 saddr
->SVE_tag_selector
= T_ATM_ABSENT
;
579 saddr
->address_format
= T_ATM_ABSENT
;
581 satm
->satm_addr
.t_atm_sap_layer2
.SVE_tag
= T_ATM_ABSENT
;
582 satm
->satm_addr
.t_atm_sap_layer3
.SVE_tag
= T_ATM_ABSENT
;
583 satm
->satm_addr
.t_atm_sap_appl
.SVE_tag
= T_ATM_ABSENT
;
585 *addr
= (struct sockaddr
*)satm
;
591 * Retrieve peer socket address
596 * so pointer to socket
597 * addr pointer to pointer to contain protocol address
600 * 0 request processed
601 * errno error processing request - reason indicated
605 atm_sock_peeraddr(struct socket
*so
, struct sockaddr
**addr
)
607 struct sockaddr_atm
*satm
;
608 struct t_atm_sap_addr
*saddr
;
609 Atm_pcb
*atp
= sotoatmpcb(so
);
613 * Return remote address, if known
615 satm
= KM_ALLOC(sizeof *satm
, M_SONAME
, M_WAITOK
);
619 KM_ZERO(satm
, sizeof(*satm
));
620 satm
->satm_family
= AF_ATM
;
621 satm
->satm_len
= sizeof(*satm
);
623 saddr
= &satm
->satm_addr
.t_atm_sap_addr
;
624 if (so
->so_state
& SS_ISCONNECTED
) {
625 cvp
= atp
->atp_conn
->co_connvc
;
626 saddr
->SVE_tag_addr
= T_ATM_PRESENT
;
627 if (cvp
->cvc_flags
& CVCF_CALLER
) {
628 ATM_ADDR_COPY(&cvp
->cvc_attr
.called
.addr
, saddr
);
630 if (cvp
->cvc_attr
.calling
.tag
== T_ATM_PRESENT
) {
631 ATM_ADDR_COPY(&cvp
->cvc_attr
.calling
.addr
,
634 saddr
->SVE_tag_addr
= T_ATM_ABSENT
;
635 saddr
->address_format
= T_ATM_ABSENT
;
638 if (saddr
->address_format
== T_ATM_ENDSYS_ADDR
)
639 saddr
->SVE_tag_selector
= T_ATM_PRESENT
;
641 saddr
->SVE_tag_selector
= T_ATM_ABSENT
;
643 saddr
->SVE_tag_addr
= T_ATM_ABSENT
;
644 saddr
->SVE_tag_selector
= T_ATM_ABSENT
;
645 saddr
->address_format
= T_ATM_ABSENT
;
647 satm
->satm_addr
.t_atm_sap_layer2
.SVE_tag
= T_ATM_ABSENT
;
648 satm
->satm_addr
.t_atm_sap_layer3
.SVE_tag
= T_ATM_ABSENT
;
649 satm
->satm_addr
.t_atm_sap_appl
.SVE_tag
= T_ATM_ABSENT
;
651 *addr
= (struct sockaddr
*)satm
;
657 * Common setsockopt processing
662 * so pointer to socket
663 * sopt pointer to socket option info
664 * atp pointer to ATM PCB
667 * 0 request processed
668 * errno error processing request - reason indicated
672 atm_sock_setopt(struct socket
*so
, struct sockopt
*sopt
, Atm_pcb
*atp
)
676 struct t_atm_aal5 aal5
;
677 struct t_atm_traffic trf
;
678 struct t_atm_bearer brr
;
679 struct t_atm_bhli bhl
;
680 struct t_atm_blli bll
;
682 struct t_atm_cause cau
;
683 struct t_atm_qos qos
;
684 struct t_atm_transit trn
;
685 struct t_atm_net_intf nif
;
686 struct t_atm_llc llc
;
687 struct t_atm_app_name appn
;
690 #define MAXVAL(bits) ((1 << bits) - 1)
691 #define MAXMASK(bits) (~MAXVAL(bits))
693 switch (sopt
->sopt_name
) {
696 err
= sooptcopyin(sopt
, &p
.aal5
, sizeof p
.aal5
, sizeof p
.aal5
);
699 if ((p
.aal5
.forward_max_SDU_size
!= T_ATM_ABSENT
) &&
700 (p
.aal5
.forward_max_SDU_size
& MAXMASK(16)))
702 if ((p
.aal5
.backward_max_SDU_size
!= T_ATM_ABSENT
) &&
703 (p
.aal5
.backward_max_SDU_size
& MAXMASK(16)))
705 if ((p
.aal5
.SSCS_type
!= T_ATM_ABSENT
) &&
706 (p
.aal5
.SSCS_type
!= T_ATM_NULL
) &&
707 (p
.aal5
.SSCS_type
!= T_ATM_SSCS_SSCOP_REL
) &&
708 (p
.aal5
.SSCS_type
!= T_ATM_SSCS_SSCOP_UNREL
) &&
709 (p
.aal5
.SSCS_type
!= T_ATM_SSCS_FR
))
712 if ((p
.aal5
.forward_max_SDU_size
== T_ATM_ABSENT
) &&
713 (p
.aal5
.backward_max_SDU_size
== T_ATM_ABSENT
) &&
714 (p
.aal5
.SSCS_type
== T_ATM_ABSENT
))
715 atp
->atp_attr
.aal
.tag
= T_ATM_ABSENT
;
717 atp
->atp_attr
.aal
.tag
= T_ATM_PRESENT
;
718 atp
->atp_attr
.aal
.type
= ATM_AAL5
;
719 atp
->atp_attr
.aal
.v
.aal5
= p
.aal5
;
724 err
= sooptcopyin(sopt
, &p
.trf
, sizeof p
.trf
, sizeof p
.trf
);
727 if ((p
.trf
.forward
.PCR_high_priority
!= T_ATM_ABSENT
) &&
728 (p
.trf
.forward
.PCR_high_priority
& MAXMASK(24)))
730 if (p
.trf
.forward
.PCR_all_traffic
& MAXMASK(24))
732 if ((p
.trf
.forward
.SCR_high_priority
!= T_ATM_ABSENT
) &&
733 (p
.trf
.forward
.SCR_high_priority
& MAXMASK(24)))
735 if ((p
.trf
.forward
.SCR_all_traffic
!= T_ATM_ABSENT
) &&
736 (p
.trf
.forward
.SCR_all_traffic
& MAXMASK(24)))
738 if ((p
.trf
.forward
.MBS_high_priority
!= T_ATM_ABSENT
) &&
739 (p
.trf
.forward
.MBS_high_priority
& MAXMASK(24)))
741 if ((p
.trf
.forward
.MBS_all_traffic
!= T_ATM_ABSENT
) &&
742 (p
.trf
.forward
.MBS_all_traffic
& MAXMASK(24)))
744 if ((p
.trf
.forward
.tagging
!= T_YES
) &&
745 (p
.trf
.forward
.tagging
!= T_NO
))
748 if ((p
.trf
.backward
.PCR_high_priority
!= T_ATM_ABSENT
) &&
749 (p
.trf
.backward
.PCR_high_priority
& MAXMASK(24)))
751 if (p
.trf
.backward
.PCR_all_traffic
& MAXMASK(24))
753 if ((p
.trf
.backward
.SCR_high_priority
!= T_ATM_ABSENT
) &&
754 (p
.trf
.backward
.SCR_high_priority
& MAXMASK(24)))
756 if ((p
.trf
.backward
.SCR_all_traffic
!= T_ATM_ABSENT
) &&
757 (p
.trf
.backward
.SCR_all_traffic
& MAXMASK(24)))
759 if ((p
.trf
.backward
.MBS_high_priority
!= T_ATM_ABSENT
) &&
760 (p
.trf
.backward
.MBS_high_priority
& MAXMASK(24)))
762 if ((p
.trf
.backward
.MBS_all_traffic
!= T_ATM_ABSENT
) &&
763 (p
.trf
.backward
.MBS_all_traffic
& MAXMASK(24)))
765 if ((p
.trf
.backward
.tagging
!= T_YES
) &&
766 (p
.trf
.backward
.tagging
!= T_NO
))
768 if ((p
.trf
.best_effort
!= T_YES
) &&
769 (p
.trf
.best_effort
!= T_NO
))
772 atp
->atp_attr
.traffic
.tag
= T_ATM_PRESENT
;
773 atp
->atp_attr
.traffic
.v
= p
.trf
;
776 case T_ATM_BEARER_CAP
:
777 err
= sooptcopyin(sopt
, &p
.brr
, sizeof p
.brr
, sizeof p
.brr
);
780 if ((p
.brr
.bearer_class
!= T_ATM_CLASS_A
) &&
781 (p
.brr
.bearer_class
!= T_ATM_CLASS_C
) &&
782 (p
.brr
.bearer_class
!= T_ATM_CLASS_X
))
784 if ((p
.brr
.traffic_type
!= T_ATM_NULL
) &&
785 (p
.brr
.traffic_type
!= T_ATM_CBR
) &&
786 (p
.brr
.traffic_type
!= T_ATM_VBR
))
788 if ((p
.brr
.timing_requirements
!= T_ATM_NULL
) &&
789 (p
.brr
.timing_requirements
!= T_ATM_END_TO_END
) &&
790 (p
.brr
.timing_requirements
!= T_ATM_NO_END_TO_END
))
792 if ((p
.brr
.clipping_susceptibility
!= T_NO
) &&
793 (p
.brr
.clipping_susceptibility
!= T_YES
))
795 if ((p
.brr
.connection_configuration
!= T_ATM_1_TO_1
) &&
796 (p
.brr
.connection_configuration
!= T_ATM_1_TO_MANY
))
799 atp
->atp_attr
.bearer
.tag
= T_ATM_PRESENT
;
800 atp
->atp_attr
.bearer
.v
= p
.brr
;
804 err
= sooptcopyin(sopt
, &p
.bhl
, sizeof p
.bhl
, sizeof p
.bhl
);
807 if ((p
.bhl
.ID_type
!= T_ATM_ABSENT
) &&
808 (p
.bhl
.ID_type
!= T_ATM_ISO_APP_ID
) &&
809 (p
.bhl
.ID_type
!= T_ATM_USER_APP_ID
) &&
810 (p
.bhl
.ID_type
!= T_ATM_VENDOR_APP_ID
))
813 if (p
.bhl
.ID_type
== T_ATM_ABSENT
)
814 atp
->atp_attr
.bhli
.tag
= T_ATM_ABSENT
;
816 atp
->atp_attr
.bhli
.tag
= T_ATM_PRESENT
;
817 atp
->atp_attr
.bhli
.v
= p
.bhl
;
822 err
= sooptcopyin(sopt
, &p
.bll
, sizeof p
.bll
, sizeof p
.bll
);
825 if ((p
.bll
.layer_2_protocol
.ID_type
!= T_ATM_ABSENT
) &&
826 (p
.bll
.layer_2_protocol
.ID_type
!= T_ATM_SIMPLE_ID
) &&
827 (p
.bll
.layer_2_protocol
.ID_type
!= T_ATM_USER_ID
))
829 if ((p
.bll
.layer_2_protocol
.mode
!= T_ATM_ABSENT
) &&
830 (p
.bll
.layer_2_protocol
.mode
!= T_ATM_BLLI_NORMAL_MODE
) &&
831 (p
.bll
.layer_2_protocol
.mode
!= T_ATM_BLLI_EXTENDED_MODE
))
833 if ((p
.bll
.layer_2_protocol
.window_size
!= T_ATM_ABSENT
) &&
834 (p
.bll
.layer_2_protocol
.window_size
< 1))
837 if ((p
.bll
.layer_3_protocol
.ID_type
!= T_ATM_ABSENT
) &&
838 (p
.bll
.layer_3_protocol
.ID_type
!= T_ATM_SIMPLE_ID
) &&
839 (p
.bll
.layer_3_protocol
.ID_type
!= T_ATM_IPI_ID
) &&
840 (p
.bll
.layer_3_protocol
.ID_type
!= T_ATM_SNAP_ID
) &&
841 (p
.bll
.layer_3_protocol
.ID_type
!= T_ATM_USER_ID
))
843 if ((p
.bll
.layer_3_protocol
.mode
!= T_ATM_ABSENT
) &&
844 (p
.bll
.layer_3_protocol
.mode
!= T_ATM_BLLI_NORMAL_MODE
) &&
845 (p
.bll
.layer_3_protocol
.mode
!= T_ATM_BLLI_EXTENDED_MODE
))
847 if ((p
.bll
.layer_3_protocol
.packet_size
!= T_ATM_ABSENT
) &&
848 (p
.bll
.layer_3_protocol
.packet_size
& MAXMASK(4)))
850 if ((p
.bll
.layer_3_protocol
.window_size
!= T_ATM_ABSENT
) &&
851 (p
.bll
.layer_3_protocol
.window_size
< 1))
854 if (p
.bll
.layer_2_protocol
.ID_type
== T_ATM_ABSENT
)
855 atp
->atp_attr
.blli
.tag_l2
= T_ATM_ABSENT
;
857 atp
->atp_attr
.blli
.tag_l2
= T_ATM_PRESENT
;
859 if (p
.bll
.layer_3_protocol
.ID_type
== T_ATM_ABSENT
)
860 atp
->atp_attr
.blli
.tag_l3
= T_ATM_ABSENT
;
862 atp
->atp_attr
.blli
.tag_l3
= T_ATM_PRESENT
;
864 if ((atp
->atp_attr
.blli
.tag_l2
== T_ATM_PRESENT
) ||
865 (atp
->atp_attr
.blli
.tag_l3
== T_ATM_PRESENT
))
866 atp
->atp_attr
.blli
.v
= p
.bll
;
869 case T_ATM_DEST_ADDR
:
870 err
= sooptcopyin(sopt
, &p
.addr
, sizeof p
.addr
, sizeof p
.addr
);
873 if ((p
.addr
.address_format
!= T_ATM_ENDSYS_ADDR
) &&
874 (p
.addr
.address_format
!= T_ATM_E164_ADDR
))
876 if (p
.addr
.address_length
> ATM_ADDR_LEN
)
879 atp
->atp_attr
.called
.tag
= T_ATM_PRESENT
;
880 atp
->atp_attr
.called
.addr
= p
.addr
;
884 err
= sooptcopyin(sopt
, &p
.addr
, sizeof p
.addr
, sizeof p
.addr
);
887 if ((p
.addr
.address_format
!= T_ATM_ABSENT
) &&
888 (p
.addr
.address_format
!= T_ATM_NSAP_ADDR
))
890 if (p
.addr
.address_length
> ATM_ADDR_LEN
)
893 /* T_ATM_DEST_ADDR controls tag */
894 atp
->atp_attr
.called
.subaddr
= p
.addr
;
897 case T_ATM_ORIG_ADDR
:
903 case T_ATM_CALLER_ID
:
907 err
= sooptcopyin(sopt
, &p
.cau
, sizeof p
.cau
, sizeof p
.cau
);
910 if ((p
.cau
.coding_standard
!= T_ATM_ABSENT
) &&
911 (p
.cau
.coding_standard
!= T_ATM_ITU_CODING
) &&
912 (p
.cau
.coding_standard
!= T_ATM_NETWORK_CODING
))
914 if ((p
.cau
.location
!= T_ATM_LOC_USER
) &&
915 (p
.cau
.location
!= T_ATM_LOC_LOCAL_PRIVATE_NET
) &&
916 (p
.cau
.location
!= T_ATM_LOC_LOCAL_PUBLIC_NET
) &&
917 (p
.cau
.location
!= T_ATM_LOC_TRANSIT_NET
) &&
918 (p
.cau
.location
!= T_ATM_LOC_REMOTE_PUBLIC_NET
) &&
919 (p
.cau
.location
!= T_ATM_LOC_REMOTE_PRIVATE_NET
) &&
920 (p
.cau
.location
!= T_ATM_LOC_INTERNATIONAL_NET
) &&
921 (p
.cau
.location
!= T_ATM_LOC_BEYOND_INTERWORKING
))
924 if (p
.cau
.coding_standard
== T_ATM_ABSENT
)
925 atp
->atp_attr
.cause
.tag
= T_ATM_ABSENT
;
927 atp
->atp_attr
.cause
.tag
= T_ATM_PRESENT
;
928 atp
->atp_attr
.cause
.v
= p
.cau
;
933 err
= sooptcopyin(sopt
, &p
.qos
, sizeof p
.qos
, sizeof p
.qos
);
936 if ((p
.qos
.coding_standard
!= T_ATM_ABSENT
) &&
937 (p
.qos
.coding_standard
!= T_ATM_ITU_CODING
) &&
938 (p
.qos
.coding_standard
!= T_ATM_NETWORK_CODING
))
940 if ((p
.qos
.forward
.qos_class
!= T_ATM_QOS_CLASS_0
) &&
941 (p
.qos
.forward
.qos_class
!= T_ATM_QOS_CLASS_1
) &&
942 (p
.qos
.forward
.qos_class
!= T_ATM_QOS_CLASS_2
) &&
943 (p
.qos
.forward
.qos_class
!= T_ATM_QOS_CLASS_3
) &&
944 (p
.qos
.forward
.qos_class
!= T_ATM_QOS_CLASS_4
))
946 if ((p
.qos
.backward
.qos_class
!= T_ATM_QOS_CLASS_0
) &&
947 (p
.qos
.backward
.qos_class
!= T_ATM_QOS_CLASS_1
) &&
948 (p
.qos
.backward
.qos_class
!= T_ATM_QOS_CLASS_2
) &&
949 (p
.qos
.backward
.qos_class
!= T_ATM_QOS_CLASS_3
) &&
950 (p
.qos
.backward
.qos_class
!= T_ATM_QOS_CLASS_4
))
953 if (p
.qos
.coding_standard
== T_ATM_ABSENT
)
954 atp
->atp_attr
.qos
.tag
= T_ATM_ABSENT
;
956 atp
->atp_attr
.qos
.tag
= T_ATM_PRESENT
;
957 atp
->atp_attr
.qos
.v
= p
.qos
;
962 err
= sooptcopyin(sopt
, &p
.trn
, sizeof p
.trn
, sizeof p
.trn
);
965 if (p
.trn
.length
> T_ATM_MAX_NET_ID
)
968 if (p
.trn
.length
== 0)
969 atp
->atp_attr
.transit
.tag
= T_ATM_ABSENT
;
971 atp
->atp_attr
.transit
.tag
= T_ATM_PRESENT
;
972 atp
->atp_attr
.transit
.v
= p
.trn
;
977 return (EPROTONOSUPPORT
); /* XXX */
979 case T_ATM_DROP_LEAF
:
980 return (EPROTONOSUPPORT
); /* XXX */
983 err
= sooptcopyin(sopt
, &p
.nif
, sizeof p
.nif
, sizeof p
.nif
);
987 atp
->atp_attr
.nif
= atm_nifname(p
.nif
.net_intf
);
988 if (atp
->atp_attr
.nif
== NULL
)
993 err
= sooptcopyin(sopt
, &p
.llc
, sizeof p
.llc
, sizeof p
.llc
);
996 if ((p
.llc
.llc_len
< T_ATM_LLC_MIN_LEN
) ||
997 (p
.llc
.llc_len
> T_ATM_LLC_MAX_LEN
))
1000 atp
->atp_attr
.llc
.tag
= T_ATM_PRESENT
;
1001 atp
->atp_attr
.llc
.v
= p
.llc
;
1004 case T_ATM_APP_NAME
:
1005 err
= sooptcopyin(sopt
, &p
.appn
, sizeof p
.appn
, sizeof p
.appn
);
1009 strncpy(atp
->atp_name
, p
.appn
.app_name
, T_ATM_APP_NAME_LEN
);
1013 return (ENOPROTOOPT
);
1021 * Common getsockopt processing
1026 * so pointer to socket
1027 * sopt pointer to socket option info
1028 * atp pointer to ATM PCB
1031 * 0 request processed
1032 * errno error processing request - reason indicated
1036 atm_sock_getopt(struct socket
*so
, struct sockopt
*sopt
, Atm_pcb
*atp
)
1041 * If socket is connected, return attributes for the VCC in use,
1042 * otherwise just return what the user has setup so far.
1044 if (so
->so_state
& SS_ISCONNECTED
)
1045 ap
= &atp
->atp_conn
->co_connvc
->cvc_attr
;
1047 ap
= &atp
->atp_attr
;
1049 switch (sopt
->sopt_name
) {
1052 if ((ap
->aal
.tag
== T_ATM_PRESENT
) &&
1053 (ap
->aal
.type
== ATM_AAL5
)) {
1054 return (sooptcopyout(sopt
, &ap
->aal
.v
.aal5
,
1055 sizeof ap
->aal
.v
.aal5
));
1062 if (ap
->traffic
.tag
== T_ATM_PRESENT
) {
1063 return (sooptcopyout(sopt
, &ap
->traffic
.v
,
1064 sizeof ap
->traffic
.v
));
1070 case T_ATM_BEARER_CAP
:
1071 if (ap
->bearer
.tag
== T_ATM_PRESENT
) {
1072 return (sooptcopyout(sopt
, &ap
->bearer
.v
,
1073 sizeof ap
->bearer
.v
));
1080 if (ap
->bhli
.tag
== T_ATM_PRESENT
) {
1081 return (sooptcopyout(sopt
, &ap
->bhli
.v
,
1082 sizeof ap
->bhli
.v
));
1089 if ((ap
->blli
.tag_l2
== T_ATM_PRESENT
) ||
1090 (ap
->blli
.tag_l3
== T_ATM_PRESENT
)) {
1091 return (sooptcopyout(sopt
, &ap
->blli
.v
,
1092 sizeof ap
->blli
.v
));
1098 case T_ATM_DEST_ADDR
:
1099 if (ap
->called
.tag
== T_ATM_PRESENT
) {
1100 return (sooptcopyout(sopt
, &ap
->called
.addr
,
1101 sizeof ap
->called
.addr
));
1107 case T_ATM_DEST_SUB
:
1108 if (ap
->called
.tag
== T_ATM_PRESENT
) {
1109 return (sooptcopyout(sopt
, &ap
->called
.subaddr
,
1110 sizeof ap
->called
.subaddr
));
1116 case T_ATM_ORIG_ADDR
:
1117 if (ap
->calling
.tag
== T_ATM_PRESENT
) {
1118 return (sooptcopyout(sopt
, &ap
->calling
.addr
,
1119 sizeof ap
->calling
.addr
));
1125 case T_ATM_ORIG_SUB
:
1126 if (ap
->calling
.tag
== T_ATM_PRESENT
) {
1127 return (sooptcopyout(sopt
, &ap
->calling
.subaddr
,
1128 sizeof ap
->calling
.subaddr
));
1134 case T_ATM_CALLER_ID
:
1135 if (ap
->calling
.tag
== T_ATM_PRESENT
) {
1136 return (sooptcopyout(sopt
, &ap
->calling
.cid
,
1137 sizeof ap
->calling
.cid
));
1144 if (ap
->cause
.tag
== T_ATM_PRESENT
) {
1145 return (sooptcopyout(sopt
, &ap
->cause
.v
,
1146 sizeof ap
->cause
.v
));
1153 if (ap
->qos
.tag
== T_ATM_PRESENT
) {
1154 return (sooptcopyout(sopt
, &ap
->qos
.v
,
1162 if (ap
->transit
.tag
== T_ATM_PRESENT
) {
1163 return (sooptcopyout(sopt
, &ap
->transit
.v
,
1164 sizeof ap
->transit
.v
));
1170 case T_ATM_LEAF_IND
:
1171 return (EPROTONOSUPPORT
); /* XXX */
1173 case T_ATM_NET_INTF
:
1175 struct t_atm_net_intf netif
;
1178 ifp
= &ap
->nif
->nif_if
;
1179 snprintf(netif
.net_intf
, sizeof(netif
.net_intf
),
1180 "%s", ifp
->if_xname
);
1181 return (sooptcopyout(sopt
, &netif
,
1189 if (ap
->llc
.tag
== T_ATM_PRESENT
) {
1190 return (sooptcopyout(sopt
, &ap
->llc
.v
,
1198 return (ENOPROTOOPT
);
1206 * Process Socket VCC Connected Notification
1209 * toku owner's connection token (atm_pcb protocol block)
1216 atm_sock_connected(void *toku
)
1218 Atm_pcb
*atp
= (Atm_pcb
*)toku
;
1221 * Connection is setup
1223 atm_sock_stat
.as_conncomp
[atp
->atp_type
]++;
1224 soisconnected(atp
->atp_socket
);
1229 * Process Socket VCC Cleared Notification
1232 * toku owner's connection token (atm_pcb protocol block)
1233 * cause pointer to cause code
1240 atm_sock_cleared(void *toku
, struct t_atm_cause
*cause
)
1242 Atm_pcb
*atp
= (Atm_pcb
*)toku
;
1245 so
= atp
->atp_socket
;
1248 * Save call clearing cause
1250 atp
->atp_attr
.cause
.tag
= T_ATM_PRESENT
;
1251 atp
->atp_attr
.cause
.v
= *cause
;
1254 * Set user error code
1256 if (so
->so_state
& SS_ISCONNECTED
) {
1257 so
->so_error
= ECONNRESET
;
1258 atm_sock_stat
.as_connclr
[atp
->atp_type
]++;
1260 so
->so_error
= ECONNREFUSED
;
1261 atm_sock_stat
.as_connfail
[atp
->atp_type
]++;
1265 * Connection is gone
1267 atp
->atp_conn
= NULL
;
1268 soisdisconnected(so
);
1271 * Cleanup failed incoming connection setup
1273 if (so
->so_state
& SS_NOFDREF
) {
1274 atm_sock_detach(so
);